Apache Kafka

Ordering Guarantees

Know exactly where Kafka promises order — and where it does not.

Kafka guarantees ordering only within a single partition. Records appended to one partition are read in the same order, identified by their offsets. Across partitions there is no global ordering, because partitions are consumed in parallel by independent threads or consumers.

Several supermarket checkout lanes: each lane processes its own customers strictly in line, but there is no single order across lanes. Put one family in one lane (a key) and that family is always served in order.

Key Concepts

1
This is why keying matters: routing all events for one entity (one orderId) to the same partition is the standard way to preserve per-entity order. The trade-off is that ordering and parallelism pull in opposite directions — a single partition is perfectly ordered but caps throughput at one consumer.
2
A subtle producer pitfall: with retries and more than one in-flight request per connection, a failed-then-retried batch can land after a later batch, reordering records. The idempotent producer fixes this and is the recommended setting whenever order matters.