Course contentsShow
← System Design
Lesson 685 of 1,91918. Message Queues and BrokersFree lesson

Message Ordering Guarantees

Per-partition ordering vs global ordering; tradeoffs with parallelism and throughput.

Message Ordering Guarantees

What you'll learn: How message brokers guarantee (or don't guarantee) the order in which messages are delivered, and what that means for your system design.


When you send multiple messages through a broker, does the consumer receive them in the same order you sent them? The answer depends on your broker's configuration and architecture.

Per-Partition Ordering

Many distributed message brokers (like Kafka) guarantee ordering within a partition but not across partitions. A partition is essentially a sequential log that preserves message order. If you send messages A, B, C to the same partition, consumers read them in that exact sequence.

Analogy: Think of checkout lanes at a grocery store. Within a single lane (partition), customers exit in the order they entered. But across multiple lanes, there's no global ordering—lane 2's customer might finish before lane 1's.

Global Ordering vs Parallelism

To achieve global ordering across all messages, you'd need a single partition (or single queue). Every message flows through one sequential channel, guaranteeing total order.

The tradeoff? You lose parallelism. With one partition, only one consumer can process messages at a time while maintaining order. Multiple consumers would risk processing messages out of sequence.

Per-partition ordering lets you scale horizontally—use multiple partitions with multiple consumers, each processing their partition in order. You gain throughput and parallelism, but lose global ordering guarantees.

Practical Impact

If your application requires strict ordering (e.g., bank transactions for a single account), route related messages to the same partition using a partition key. For loosely coupled events where global order doesn't matter, distribute across partitions for better performance.

Key Takeaway: Per-partition ordering preserves sequence within logical groups while enabling parallel processing; global ordering guarantees total sequence but sacrifices throughput and horizontal scalability.