BackendBench
Coffee
Java · streaming

Kafka partition calculator

Which partition does this key land on? Is my key distribution skewed? What happens to ordering if I add partitions? The same murmur2 hash Kafka uses, in your browser.

How Kafka picks a partition

For a record with a key, the default partitioner computes murmur2(keyBytes), masks off the sign bit, and takes it modulo the partition count. The same key therefore always goes to the same partition as long as the partition count does not change, which is what gives you per-key ordering.

That simplicity has three practical consequences. A few very busy keys create hot partitions while others sit idle. Adding partitions moves most keys, so ordering for a key can break across the change. And the number of consumers in a group is useful only up to the number of partitions, since each partition is read by one consumer at a time.

The murmur2 implementation here is a direct port of Kafka's Utils.murmur2, verified against the test vectors in Apache Kafka's own test suite. The distribution, repartition and assignment tabs let you answer these capacity questions with your real keys before you change a topic.

Frequently asked questions

How does Kafka choose a partition for a keyed message?

The default partitioner hashes the key bytes with murmur2, clears the sign bit, and takes the result modulo the number of partitions. This tool uses the same algorithm as Kafka's Utils.murmur2 and is tested against Kafka's own test vectors.

Why does adding partitions break ordering?

The partition is hash % N. When N changes, most keys map to a different partition, so records for one key end up split across two partitions and per-key ordering is lost for a while. The Repartition tab shows what share of keys moves.

What about null keys?

Records without a key are not hashed. Modern clients use a "sticky" approach that fills a batch for one partition before moving on, so a key-less topic is balanced by volume, not by hash. This tool covers keyed records.

Does a custom partitioner change the result?

Yes. If your producer sets partitioner.class or you send to an explicit partition, this calculator does not apply. It models the default behaviour.

More tools you might need