Skip to content
Kafka Is Fun

BeginnerCore Concepts

How does Kafka guarantee message ordering?

Reference answer

Kafka guarantees ordering within a single partition: a consumer of a topic-partition reads its events in exactly the order they were written. Events with the same key go to the same partition, so they stay in order relative to each other. Kafka makes no ordering promise between different partitions, so a consumer reading several partitions may see their events interleaved. If you need a total order for a whole topic, a single partition is the way to get it, but then only one consumer in a group can read it at a time, so parallelism is lost. On the producer side, retries can reorder records unless ordering is protected: it is preserved if retries are disabled or if idempotence is enabled (the default), which requires max.in.flight.requests.per.connection of 5 or less. A common approach is to key records by the entity whose order matters and rely on per-key ordering.

Expected key concepts: within a single partition, same key, same partition, single partition, total order, between different partitions, idempotence, max.in.flight.requests.per.connection, retries

How did that feel?

Your own verdict, not the score. It shows up next to this question in the list, so you can come back to the shaky ones.