Kafka: The default partitioner is murmur2 of the key, modulo partitions

Deterministic, which is why the same key always lands in the same partition - and why adding partitions reshuffles everything.

Code
// org.apache.kafka.common.utils.Utils
partition = Utils.toPositive(Utils.murmur2(keyBytes)) % numPartitions;
Output
key "order-42", 6 partitions -> partition 0
key "order-42", 8 partitions -> partition 4

Repartitioning breaks ordering for keys in flight.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11