Designing Messaging and Event Architectures: Queues, Topics, Events, Streaming and Delivery Guarantees
Three Kinds of Messages
| Kind | Meaning | Example | Service |
| Command / message | Please do this. One receiver, must be processed | ProcessPayment | Service Bus queue |
| Event | This happened. Many possible receivers | BlobCreated | Event Grid, Service Bus topic |
| Stream | Large ordered flow of events for analysis | Telemetry | Event Hubs |
Decision Table
| Need | Choose |
| Reliable work queue with retries and dead-lettering | Service Bus queue |
| Fan-out to many subscribers with filters | Service Bus topic or Event Grid |
| React to Azure resource changes | Event Grid |
| Millions of events per second, replay, Kafka clients | Event Hubs |
| Simple, huge, cheap queue, over 80 GB, no advanced features | Storage Queue |
| Ordering per customer | Service Bus sessions or Event Hubs partition key |
Delivery Guarantees
- Most services give at-least-once delivery. A message can arrive more than once
- At-most-once (do not retry) can lose messages
- Exactly-once processing is built by you using idempotent handlers or deduplication
Design Rules
- Make consumers idempotent: use a message id and upsert or check a processed-ids table
- Set max delivery count and a dead-letter queue, and alert when it is not empty
- Use time-to-live so old messages expire
- Use competing consumers: many workers read one queue and scale by queue length
- Keep messages small. Store big payloads in Blob and send a claim check reference
- Use sessions or partition keys only when ordering is required, because they limit parallelism
- Use the outbox pattern so database changes and messages do not diverge
Patterns
| Pattern | Idea |
| Queue-based load leveling | Queue absorbs spikes so backend processes at steady pace |
| Competing consumers | Parallel workers share a queue |
| Publish/subscribe | Topic copies a message to each subscription |
| Priority queue | Separate queues or topics for urgent work |
| Saga | Long business transaction across services using events and compensations |
| Claim check | Send a pointer to large data |
Security and Networking
- Entra ID and managed identities instead of connection strings
- Premium Service Bus for private endpoints, bigger messages and dedicated capacity
- Geo-disaster recovery pairing for namespaces. Check geo-replication features and current options
Scenario
Order system: web app puts an OrderPlaced message on a Service Bus topic. Subscriptions for billing, inventory and email each get a copy. Billing uses a session per customer for ordering. Failed messages go to dead-letter and raise an alert. Warehouse devices stream scans to Event Hubs for analytics.
Practice
- Classify five interactions as command, event or stream
- Design an idempotent payment handler
- Choose the service for 50,000 messages per second of telemetry
Conclusion
Pick the messaging service by message kind. Assume at-least-once delivery, make handlers idempotent, handle poison messages with dead-letter queues and use patterns such as competing consumers and claim check.
Quick Summary: kinds; decisions; guarantees; rules; patterns; security; scenario.