Skip to content
Kafka Is Fun

IntermediateOperations

How does Kafka guarantee message ordering with multiple producers?

Reference answer

Kafka only orders records within a single partition: a partition is an append-only log and the leader chooses the order in which records land in it. One producer's sends to a partition are appended in the order they were sent; with enable.idempotence=true (the default) that holds even with retries and up to max.in.flight.requests.per.connection=5, while without idempotence retries with more than one in-flight request can reorder records. With multiple producers writing to the same partition there is no coordination between them, so their records interleave in arrival order at the leader. If you need a causal ordering across producers (A must be seen before B), send the related records through a single producer to one partition (for example by using the same key), or put timestamps or sequence numbers in the payload and reconcile at the consumer. Consumers read a partition in log order, and there is no ordering guarantee across partitions.

Expected key concepts: single partition, interleave, arrival order, causal ordering, single producer, same key, enable.idempotence, max.in.flight.requests.per.connection, timestamps, sequence numbers

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.