esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Sequential Convoy: Keep Related Messages in Order Without Stopping Everything

How a messaging system can handle many groups at once while each group's messages are handled strictly in order.

In short

Sequential Convoy lets a messaging system handle many groups at once while each group's related messages are still handled strictly in order.

11 min readFree

What You Will Learn

Many software systems send work as messages. A message is a small piece of data that says something happened or asks for work to be done. Messages wait in a queue, which is a holding line. A consumer is a program that reads messages from the queue and does the work. When you add more consumers, the system handles more messages at once. The cost is that two messages about the same thing can be handled in the wrong order. This lesson teaches Sequential Convoy, a pattern that keeps related messages in order while still letting many groups run in parallel.

Key words

Message
A small piece of data that reports an event or asks for work.
Queue
A holding line where messages wait until a consumer reads them.
Consumer
A program or worker that reads messages from a queue and does the work.
Broker
The service that stores messages and hands them to consumers, such as Azure Service Bus or Apache Kafka.
FIFO
First in, first out. Items leave in the same order they arrived.
Group key
A label on each message, such as an order ID, that says which related group the message belongs to.
Session
Azure Service Bus's name for a group of related messages that one consumer handles in order.
Partition
A separate lane inside a Kafka topic. Kafka keeps order inside each lane, not across lanes.
Hot key
A group key that receives far more messages than the other keys.
Dead-letter queue
A side queue where messages go after they fail too many times.
Sequential Convoy
A messaging pattern that handles each group's messages one at a time, in order, while different groups run in parallel.

By the end, you should be able to say why plain parallel queues can break order, how a group key fixes that, and what new costs the fix brings.

Why Do Parallel Workers Break Order?

Imagine an online shop. Each order sends a few messages: create the order, add an item, change the address, and cancel. The queue holds these messages for all customers mixed together. You want many workers so that the shop keeps up on busy days. You also want each order's steps to happen in the right sequence. Those two goals pull against each other, and the simple designs each fail in a different way.

  • One worker

    A single consumer reads messages one at a time, so the order is always right. But it can only do as much work as one worker can manage, so the line grows when traffic rises.

  • Many workers

    Several consumers read from the same queue together. The system gets faster, but two workers can take two messages for the same order at the same moment. One may finish before the other, and the order's data can end up wrong.

  • Mixed order

    The queue itself is in arrival order, but the messages for many orders are woven together. Reading the queue in order does not keep each order's steps in order once work is shared out.

Azure's pattern guide describes this gap. Competing consumers, where many workers pull from one queue, spread the load well. But they give up the ordering that each group needs. Sequential Convoy was designed to close that gap.

A Concrete Failure

Take two messages for order 42. The first says create the order. The second says update its address. If one worker picks up the update before the creation has been saved, the update may find no order to change. The result is an error, or a record that is missing data. Nothing crashed, but the state is now wrong.

How Does Sequential Convoy Work?

The pattern has one central idea. Each message carries a group key, and the broker makes sure one group is handled by one consumer at a time. Different groups are free to run side by side. The steps below show the flow from the producer, which is the program that sends messages, to the consumers.

  1. 1

    Tag each message with a group key

    The sender puts a key on every message, such as the order ID or the bank account number. Messages about the same thing get the same key.

  2. 2

    Let the broker group the messages

    The broker sorts the incoming messages into groups by key. Messages with the same key stay in arrival order inside their group.

  3. 3

    Lock one group to one consumer

    A consumer takes a lock on a group. While it holds the lock, no other consumer receives that group's messages. The consumer works through them one by one.

  4. 4

    Run other groups at the same time

    Other consumers lock other groups and work on them in parallel. Adding consumers adds capacity, as long as there are enough active groups.

  5. 5

    Close the group and release the lock

    When the group is finished, or the consumer stops for another reason, it releases the lock. The next available consumer can then take the group.

Sessions and Partition Keys

Different brokers use different names for the same idea. Azure Service Bus calls the group a session, and Azure's guide says that message sessions are a built-in implementation of the pattern on Azure. Apache Kafka uses a partition key. Kafka sends all messages with the same key to the same partition. A partition is then read by only one consumer in a consumer group, so the order inside that lane is kept.

What Does Order Mean Here?

The order is only promised inside one group. Messages for order 42 stay in order, and messages for order 43 stay in order. There is no promise about which of the two finishes first. That is the trade: you give up global order to gain parallel speed.

Tradeoffs You Must Manage

Sequential Convoy is not free. Each benefit comes with a cost that a designer must plan for. The four costs below are ones a designer should plan for.

  • A slow or failing message blocks its group

    Because the group is strictly ordered, later messages wait behind the slow or broken one. A message that keeps failing can stop its whole group until someone deals with it.

  • Hot keys limit throughput

    If one key gets most of the traffic, one consumer carries most of the load. The rest of the consumers sit idle, and the system cannot speed up by adding more workers.

  • Group size and lifetime

    A group can grow very large, and a session may stay open for a long time. Designers must decide how long a group lives, and when its saved state can be cleared.

  • End-of-group markers

    A consumer needs to know when a group is finished. A common approach is to mark the first message as a start, and the last message as an end, so the consumer can close the group cleanly.

Tip

Measure how long one message takes to process. Throughput for one group can never beat one message divided by that time, so a slow handler caps the speed of its whole group.

Quick check

A shipping app uses the store ID as the group key for all order messages. One large store creates 80 percent of all orders. What is the main problem?

How Do You Handle a Stuck Message?

Azure Service Bus gives each queue a dead-letter queue. After a message fails too many times, the broker moves it aside so the rest of the session can continue. The default limit in Azure Service Bus is ten deliveries. Moving a message back later can change its place in the order, so the team must plan how to fix and replay it. Retry rules are a separate topic and are not covered here.

Worked Example: One Food Order at a Time

Picture a food-delivery app. A customer places an order, the restaurant accepts it, a courier picks it up, and the courier delivers it. This example is an illustration of the idea, not a description of how any named company builds its system. The app uses the order ID as the group key, so every event for one order lands in the same group.

  1. 1

    The customer places an order

    The app sends a placed event with order ID 1001 as the group key.

  2. 2

    The restaurant accepts

    The app sends an accepted event with the same key, 1001. The broker places it after the placed event in that group.

  3. 3

    The courier picks up and delivers

    The picked-up and delivered events also carry key 1001. One worker handles all four events, one after another.

  4. 4

    Other orders run at the same time

    Orders 1002, 1003, and so on get their own groups. Other workers handle them at the same moment, so many orders finish in parallel.

The code below uses plain Python to show the grouping step. It sorts events by key and keeps the arrival order inside each key. A real broker does this work for you, but the idea is the same.

group_events.py
events = [
    ("order-1", "placed"),
    ("order-2", "placed"),
    ("order-1", "accepted"),
    ("order-2", "picked up"),
    ("order-1", "picked up"),
    ("order-1", "delivered"),
]
groups = {}
for key, event in events:
    groups.setdefault(key, []).append(event)
for key, items in groups.items():
    print(key, "->", " then ".join(items))

Output

order-1 -> placed then accepted then picked up then delivered
order-2 -> placed then picked up

Each order keeps its own steps in sequence, and the two orders do not wait on each other. If order 1 is slow at the restaurant, order 2 can still be picked up on time. That is the main benefit of Sequential Convoy in this app.

When Should You Use It, and When Not?

Sequential Convoy fits when order matters inside a related set and not across the whole system. It is a poor fit when the messages do not depend on each other. Use the questions below to decide.

  • Use it when order matters within a set

    Events for one order, one bank account, or one device should be applied in the order they happened. Here the order is part of the correct result.

  • Skip strict order when messages are independent

    If each message can be handled on its own, or if handling them twice or out of order gives the same result, the ordering adds cost for no gain. Use plain parallel consumers instead.

  • Avoid global order unless you truly need it

    Putting every message in one group forces one consumer to do all the work. Third-party write-ups note that one partition gives global order at the cost of throughput.

Tip

Ask who needs to be in order. If the answer is one entity, such as an order or an account, use that entity's ID as the key. If the answer is everyone, rethink the design before you pay the throughput cost.

Choosing the Key

The key sets how much parallel work the system can do. A key that is too broad, such as one customer ID for all of that customer's orders, limits parallelism. A key that is too narrow, such as a random ID per message, gives little meaningful ordering benefit. Good keys have many distinct values, spread traffic evenly, and match the thing whose steps must stay in order.

Check Your Understanding

Quick check

A bank app sends 'deposit $100', 'withdraw $150', and 'close account' messages for each customer account. Ten parallel workers read one queue. Sometimes an account is closed before its withdrawal is processed. What change fixes this without making all customers wait for one worker, and why?

To sum up, Sequential Convoy tags related messages with a group key, lets one consumer work through each group in order, and lets different groups run at once. You trade global order for parallel speed. Watch for slow messages, hot keys, group lifetime, and end markers, and only use the pattern when the order inside a group truly matters.

Sources

How is this lesson?

Last updated on 18 November 2026

Learn with me

Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.