Kafka: Key cardinality decides whether partitions stay balanced

Few distinct keys means most partitions sit idle while one does all the work.

Code
// 3 distinct keys, 12 partitions
send("orders", "IN", ...);
send("orders", "US", ...);
send("orders", "UK", ...);
Output
At most 3 of 12 partitions ever receive data.
Parallelism is 3, whatever the partition count says.
Use a key with high cardinality - order id, not country.
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