Protocols & Binary Serialization

Kafka partition calculatorfrom exact key bytes

Check one key against a partition count. The selected algorithm is Java-compatible Murmur2.

Kafka partition calculator

Serialized key input

Text is preserved exactly, including spaces and line breaks. An empty byte key is valid; select Null key for an absent key.

Partition result

Partition (zero-based)
9
Byte count
5
Signed 32-bit hash
2132663229
Unsigned 32-bit hash
2132663229
Hash with sign bit cleared
2132663229

Calculation steps

  1. Decode the key into 5 bytes.
  2. Murmur2 with seed 0x9747b28c → 2132663229.
  3. 2132663229 & 0x7fffffff → 2132663229.
  4. 2132663229 % 12 → partition 9.

Key bytes in hexadecimal

68 65 6c 6c 6f

Calculation stays in this browser tab. No key is sent or saved, and no Kafka cluster is contacted.

Options

Applies to Java-compatible keyed Murmur2 routing. Explicit partitions, ignored keys, custom serializers or another partitioner can change the actual destination.

Calculation complete.

A producer sends a customer record to an unexpected partition, even though the visible key looks right. This Kafka partition calculator helps separate a byte mismatch from a routing mismatch: inspect the serialized key, then compare the hash and current partition count.

Kafka key to partition mapping depends on the bytes supplied by the serializer. A numeric key serialized as four binary bytes differs from the same number typed as text. Use hexadecimal or Base64 when reproducing a non-string serializer.

Why use this Kafka partition calculator?

Compare bytes before blaming the partitioner

The Kafka partition calculator accepts text and two binary encodings. Equivalent bytes produce the same hash regardless of how you entered them. The hexadecimal preview reveals a trailing newline, a zero byte or a multibyte character that a plain text comparison can miss.

Three input channels converge on identical byte blocks and one shared result.

Keep missing keys separate from empty keys

An empty string encoded as UTF-8 is a real zero-length byte array. A null key has no byte array at all. One follows the chosen deterministic hash formula; the other depends on producer state. The result panel shows this distinction instead of inventing a destination.

A byte key follows one solid path to a partition; a missing key has several dashed possible paths.

Reproduce the producer’s assumptions

01

Start after serialization

Choose UTF-8 only if those are the bytes your producer writes. Hex accepts ASCII whitespace and complete byte pairs without a 0x prefix. Standard Base64 requires its normal padding; changing the encoding reinterprets the input instead of converting it.

02

Use the current total partition count

The default 12 is an example, not a sizing recommendation. Partitions are numbered from zero, so 12 partitions means destinations 0 through 11. Changing the divisor can change a key’s destination while its hash stays identical.

03

Check the signed value and the mask

Load abc or foobar from Test vectors and compare the shown signed hash with the fixed reference. Automatic mode waits 350 ms after edits. Turn it off to calculate with Ctrl/Cmd + Enter; export stays disabled while the result is stale.

A byte-level routing trace

Kafka’s fixed Murmur2 variant

The engine uses seed 0x9747b28c, little-endian four-byte blocks and 32-bit multiplication. Signed and unsigned hash displays describe the same bits. Routing clears the sign bit with 0x7fffffff before modulo; Math.abs is a different operation and can produce another partition.

Three inputs, one byte sequence

UTF-8 preserves spaces, line breaks, case and Unicode form. Hex and standard Base64 let you supply arbitrary serialized key bytes, including 00 and ff. Invalid pairs, malformed padding and noncanonical final Base64 bits fail explicitly instead of silently changing your input.

Reference values and complete reports

The test-vector drawer includes abc, foobar and 21 with fixed Apache Kafka expectations. The byte preview initially shows 100 bytes and expands by 100. A JSON report includes all bytes, the algorithm, encoding, key type, partition count and intermediate numeric values.

Where the formula applies

A named algorithm, not every client default
Only Java-compatible Murmur2 is implemented. librdkafka may use CRC32-based routing by default; custom partitioners and partitioner.ignore.keys can bypass this formula. An explicitly assigned partition also takes precedence. Compare your producer configuration before treating a mismatch as a bug.
No prediction for a null key
Selecting Null key preserves but ignores the text input. No hash or fixed partition is reported because sticky, random and other runtime strategies require producer state. The literal text null remains four UTF-8 bytes in Byte key mode.
Serialization is supplied, not inferred
This tool does not execute Avro, Protobuf, integer serializers or schema registry lookups. It also does not trim or normalize text. Unpaired Unicode surrogates are rejected to avoid silent browser replacement. Supply the actual bytes when your serializer behaves differently.
Browser limits are separate from Kafka limits
The input budget is 196608 UTF-16 code units and 65536 decoded bytes. Partition count must be a decimal integer from 1 to 2147483647. There is no file, URL or batch import; these limits protect local responsiveness and say nothing about a broker’s message limit.
No capacity planning or historical movement
This calculation neither recommends a partition count nor determines a broker, consumer or offset. Increasing the count can remap future records; existing messages remain where they were written. A single key is insufficient to estimate distribution or guarantee ordering across partitions.

Kafka partition calculator: common questions

Which partition will a Kafka producer choose for a key?

For a non-null serialized key and the chosen keyed routing policy, compute Murmur2, clear the sign bit, then take the remainder modulo the total partition count. For example, abc has signed hash 479470107 and maps to partition 3 with 12 partitions. Use producer metadata to confirm the actual count.

Can different keys end up in the same partition?

Yes. Many possible keys map into a finite number of partitions, so sharing a destination is expected. This does not necessarily mean the full 32-bit hashes collide: different positive hashes can have the same remainder. A shared partition says nothing about key equality.

Why do records with the same key reach different partitions?

Compare the serialized bytes, total partition count and producer partitioner configuration. Different language clients can use different algorithms; the same displayed string may also serialize differently. An explicit partition or ignored-key setting can override key hashing. Consumer rebalancing changes ownership, not this hash formula.

Is a key required when sending a Kafka message?

No. Kafka producers can send records without a key. Whether that is appropriate depends on the application’s grouping and ordering requirements. This page lets you select an absent key explicitly and then reports that the destination cannot be determined by the keyed Murmur2 formula alone.

How is the partition chosen when no key is supplied?

It depends on the client, version and configuration, as well as runtime state such as batching. Modern Java producers can use sticky behavior; other clients have their own policies. This calculator intentionally returns no fixed destination for null instead of replaying an old round-robin assumption.

Does Kafka's Murmur2 seed change between runs?

The Kafka Murmur2 variant uses the fixed seed 0x9747b28c. With identical serialized bytes, the hash is repeatable across runs. That does not freeze the final destination: changing the partition count changes the modulo operation, and a different partitioner may use another algorithm.

Found a calculation or validation issue?

Compare your next producer key

Use the Kafka partition calculator with bytes captured from your serializer, then compare the intermediate values with your producer’s keyed routing implementation.