Skip to content
Kafka Is FunProgress

Lesson 2 of 5

Partitioning Strategies

Without a key, the producer uses the sticky partitioner (Kafka 2.4+): it sticks to one partition until the batch is full, then switches. This maximizes batching efficiency vs round-robin. With a key, the default partitioner uses murmur2 hash of the key modulo partition count. Custom partitioners implement the Partitioner interface. Note: partition count changes will cause the same key to map to a different partition!

Key configuration

broker / client configurationproperties
partitioner.class=org.apache.kafka.clients.producer.internals.DefaultPartitioner
partitioner.ignore.keys=false — respect key-based routing

Try it in the simulator

Guided scenarios for this module — the simulator opens with the exercise already running.