Azure Service Bus is Microsoft's enterprise messaging service: durable, ordered, transactional message queuing and publish-subscribe. Understanding its architecture shapes how it is used correctly.

Queues vs topics

Azure Service Bus queues provide one-to-one message delivery: one sender, one receiver, each message consumed once. Topics with subscriptions provide one-to-many delivery: one sender, multiple subscription receivers, each receiving a filtered copy of the message. Topics are the right choice when multiple downstream services need to act on the same event independently. The filter rules on subscriptions allow subscribers to receive only messages with specific properties.

Message sessions for ordered processing

Service Bus message sessions provide ordered, exclusive processing of messages with the same session ID. Use case: processing all messages for a specific entity (a customer ID, an order ID) in order and by one consumer at a time. Without sessions, a queue distributes messages to available consumers without ordering guarantees. Sessions allow building FIFO queuing within a specific entity boundary on top of Service Bus.

Duplicate detection

Service Bus supports duplicate detection: the broker tracks message IDs for a configurable window (up to 7 days) and discards messages with duplicate IDs within the window. Enable duplicate detection when producers may retry failed sends and the application cannot tolerate duplicate processing at the broker level. The producer sets a consistent MessageId for each logical message; the broker ensures idempotent delivery.

Deferred messages

Service Bus message deferral allows a consumer to receive a message and set it aside for processing later, without the message returning to the queue for other consumers. The deferred message must be retrieved explicitly by its sequence number. Use case: a workflow step that cannot proceed because a prerequisite has not been met (a payment message arrives before the order it refers to). The step defers the payment and processes it when the order arrives.