The scope of ordering
A broker guarantees order only within a single partition, not across the whole topic. Each partition is an append only log, so messages in it are consumed in the exact sequence they were written. Across partitions there is no global order.
Keys decide placement
A producer chooses a partition by hashing a message key. All messages with the same key, say one user id, land in the same partition and therefore stay ordered relative to each other. Picking a good key is how you get the ordering you need.
What can break order
- Retries with in flight requests: a retried earlier message can land after a later one unless max in flight is one or idempotence is enabled.
- Repartitioning: changing partition count rehashes keys, breaking continuity for existing keys.
The throughput tension
Strict global order would force a single partition and kill parallelism. Per key ordering across many partitions is the practical compromise: order where it matters, parallelism everywhere else.
Flow
Key idea
Order holds only within a partition; hashing a stable key keeps related messages ordered while many partitions preserve parallelism.