Scenario 01.2.2 · Producer partitioners
Kafka producer partitioners: keyed, round-robin and sticky
Keyed records co-partition by hash; keyless records spread (round-robin) or cluster per batch (uniform-sticky).
Run this scenario in the playgroundIdle. t+0.000s
One producer, a 4-partition topic. Default partitioner.
Open at this step: step 1, IdleKeyed: same key, same partition. t+0.700s
Default partitioner, keyed records. K1 was produced twice and both copies hashed to the same partition (co-partitioning ⇒ per-key ordering).
Open at this step: step 2, Keyed: same key, same partitionRound-robin: even spread. t+1.400s
No-key records cycle across all four partitions, one step per record - an even load spread.
Open at this step: step 3, Round-robin: even spreadUniform-sticky: one partition per batch. t+2.400s
No-key records stick to a single partition, then the sticky partition moves on for the next batch. In Kafka 4.x this is the default partitioner's keyless mode (KIP-794), which switches only after batch.size bytes, to a random load-weighted partition; the simulator switches per batch to make it visible.
Open at this step: step 4, Uniform-sticky: one partition per batchWhat you start with
The partitioner decides which partition each record lands on. Across three phases on a 4-partition topic you see all three behaviors: keyed records hash to a partition (the two K1 writes co-partition), round-robin spreads keyless records one-per-partition, and uniform-sticky (in Kafka 4.x, the default partitioner's keyless behaviour) packs records onto one partition before switching.
Step by step
- Idle t+0.000s One producer, a 4-partition topic. Default partitioner. Open at this step: step 1, Idle
- Keyed: same key, same partition t+0.700s Default partitioner, keyed records. K1 was produced twice and both copies hashed to the same partition (co-partitioning ⇒ per-key ordering). Open at this step: step 2, Keyed: same key, same partition
- Round-robin: even spread t+1.400s No-key records cycle across all four partitions, one step per record - an even load spread. Open at this step: step 3, Round-robin: even spread
- Uniform-sticky: one partition per batch t+2.400s No-key records stick to a single partition, then the sticky partition moves on for the next batch. In Kafka 4.x this is the default partitioner's keyless mode (KIP-794), which switches only after batch.size bytes, to a random load-weighted partition; the simulator switches per batch to make it visible. Open at this step: step 4, Uniform-sticky: one partition per batch
The takeaway
A record's partition comes from its key (same key → same partition, preserving per-key order) or, when keyless, from the partitioner strategy - round-robin for even spread, sticky for fewer, fuller batches.
Configs in this scenario
-
batch.The most bytes the producer puts in one batch for a partition (default 16384); a batch goes out when it is full or when linger.ms runs out, whichever comes first. How batch.size workssize
Embed this scenario
Paste this into a blog post, a course page or your team's docs. The scenario plays inside your page, and the link under it points readers to this walkthrough.
<iframe src="https://monedula.dev/kafka-simulator/embed/?scenario=01.2.2" title="Kafka Simulator: Producer partitioners" width="100%" height="520" style="border:1px solid #d0d0d0;border-radius:8px" loading="lazy"></iframe>
<p><a href="https://monedula.dev/kafka-simulator/scenarios/producer-partitioners/">Kafka producer partitioners: keyed, round-robin and sticky</a></p> Further reading
More in Producers & EOS
- Kafka producer acks=0: fire and forget, silent data loss
- Kafka producer acks=1: acknowledged by the leader only
- Kafka acks=0 vs acks=1 vs acks=all on a degraded ISR
- Kafka acks=1 data loss: min.insync.replicas does not help
- Kafka linger.ms vs batch.size: when the producer sends
- Kafka compression.type: fewer, larger producer batches
- Kafka buffer.memory and max.block.ms: producer backpressure
- Kafka idempotent producer: retrying NOT_ENOUGH_REPLICAS
- Kafka enable.idempotence=false: a retry writes a duplicate
- Kafka idempotent producer dedup vs a plain producer
- Kafka max.in.flight.requests.per.connection and ordering