Deterministic, which is why the same key always lands in the same partition - and why adding partitions reshuffles everything.
// org.apache.kafka.common.utils.Utils
partition = Utils.toPositive(Utils.murmur2(keyBytes)) % numPartitions;
key "order-42", 6 partitions -> partition 0
key "order-42", 8 partitions -> partition 4
Repartitioning breaks ordering for keys in flight.
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