What ordering does a partitioned log guarantee, and how do you get ordering across keys if you need it?
Sketch your own answer first, then compare it with the one below.
A strong answer
Messages in the same partition are delivered in the order they were appended. Because the key picks the partition, messages with the same key are ordered. There is no guarantee between partitions.
For a global order you can use a single partition, which caps throughput, or you can attach a sequence number or timestamp and reorder downstream, accepting buffering and some delay. Often the real requirement is order per entity, and the key already gives it.
Separate what needs order from what does not. Producer retries can also reorder messages unless the producer limits sends in flight.
Sources
- Jay Kreps, Neha Narkhede, Jun Rao (2011). Kafka: a distributed messaging system for log processing.
- Tyler Akidau and others (2015). The Dataflow Model.
- Martin Kleppmann (2017). Designing Data-Intensive Applications.