Get startedGet started for free

Sessions, auto-forwarding, and partitions

1. Sessions, auto-forwarding, and partitions

In this video, you’ll go beyond the basics of Azure Service Bus and will learn some advanced concepts.

2. Session overview

Let's start with sessions. Sometimes, we want things to get delivered in order. For example, items need to be added to a user's shopping cart in the same order as the user added them. Otherwise, the user of the system would be confused and would assume the system is broken. That's what sessions are for.

3. Sessions overview

This feature that gives you per-key ordering. You tag related messages with a Session ID, like all updates for the same order. Service Bus delivers one session to exactly one consumer at a time, so those messages stay in sequence. While you process a session, you can keep lightweight state and resume exactly where you left off if the worker restarts. The result is clean, per-customer first-in-first-out processing without sacrificing horizontal scale across many concurrent sessions.

4. Deal lettering and auto-forwarding

Next comes reliability with dead-lettering and auto-forwarding. When a message can't be completed, perhaps because it exceeded its delivery count or couldn't be parsed, Service Bus moves it to the dead-letter queue. That keeps your path unblocked and your backlog healthy. Auto-forwarding then lets you pipe dead-lettered messages to a separate queue or a topic subscription. You can fan those problem messages out to a diagnostics flow, capture them for audit, or trigger a retry queue for reprocessing, without adding custom rerouting code to your primary consumers.

5. Duplicate detection

Let's now look closely at duplicate detections. Network connections can break, which causes clients to time out and resend the message. Doing work twice could be problematic. You don't want to be double-charged for your shopping! To avoid doing this, we can enable duplicate detection and set a time window. Each message carries an ID. If Service Bus sees the same ID again within that window, it discards the duplicate. As the result, you get the message processed once, even when the network isn't playing nice.

6. Partitions for high throughput

Finally, we'll look at partitioning for availability and throughput. A partitioned queue or topic spreads messages across multiple brokers under the hood, so several flows of messages are processed in parallel. It's like having multiple lanes on the highway instead of just one. This also improves resiliency. One node can fail without taking the entity down. Consumers still use the same API. Service Bus manages the distribution. Therefore, clients don't have to use a different connection string.

7. Putting it all together

Put it together and you have a robust pattern. Sessions to preserve order where it matters, dead-lettering plus auto-forwarding to quarantine and route problem messages, duplicate detection to prevent rework, and partitioning to keep the whole system fast and highly available.

8. Let's practice!

Let's see how these concepts are applied in practice.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.