Message Queues & Streaming • Message Ordering & PartitioningEasy⏱️ ~2 min
Message Ordering Scope: Partitions vs Global Order
Definition
Message ordering in distributed systems is guaranteed only within a partition, not across the entire system. A partition is an append-only, ordered log where messages maintain strict First In First Out (FIFO) semantics.
💡 Key Takeaways
✓Ordering is scoped to partitions only. Each partition maintains strict FIFO order, but messages across different partitions can be interleaved in any sequence.
✓Single consumer per partition rule ensures sequential processing. Consumer groups assign each partition to exactly one consumer at any moment to preserve order.
✓Global ordering requires single partition or consensus, capping throughput. One partition limits you to one consumer's processing speed; consensus adds RTT coordination overhead per batch.
✓Production systems prefer per key ordering at scale. LinkedIn runs thousands of partitions processing trillions of messages daily, maintaining per user order while enabling massive parallelism.
✓Partition assignment uses deterministic hashing. hash(key) mod partition_count maps the same key to the same partition consistently, ensuring related messages stay together in order.
📌 Interview Tips
1LinkedIn partitions by member ID: all profile updates, posts, and activity for user 12345 go to partition hash(12345) mod 1000, preserving per user event order while processing millions of users in parallel
2Amazon Kinesis shards: each shard handles up to 1 MB/s writes and 2 MB/s reads with ordering per partition key; scaling from 10 to 100 shards increases total throughput 10x while maintaining per key order
3Banking transactions: account 9876 balance updates must be ordered (deposit before withdrawal check), so all transactions for account 9876 are keyed to the same partition ensuring sequential processing