Kafka reference
Keys and partitions
Routing
| Record has | Default producer does | Order you can rely on |
|---|---|---|
| A key | toPositive(murmur2(keyBytes)) % numPartitions | Per key, while the partition count is unchanged |
| No key | Sticks to one partition for about batch.size bytes, then moves | Per partition only, nothing per key |
| An explicit partition | Uses that partition | Per partition |
Producer settings
| Config | Default | Effect |
|---|---|---|
partitioner.class | null | Null uses the built-in logic. Can be RoundRobinPartitioner or your own Partitioner. |
partitioner.ignore.keys | false | If true, keys are not used to choose a partition. |
partitioner.adaptive.partitioning.enable | true | Sends more to partitions on faster brokers. |
Rules worth memorising
- Order exists within a partition, never across a topic.
- Same key means same partition. Different keys may still share one.
- Total order across a topic needs exactly one partition.
- Partition count can only increase. To reduce it, create a new topic.
- Growing remaps keys, and existing data does not move.
Commands
kafka-topics.sh --bootstrap-server HOST:9092 --create --topic T --partitions 3 --replication-factor 1
kafka-topics.sh --bootstrap-server HOST:9092 --describe --topic T
kafka-topics.sh --bootstrap-server HOST:9092 --alter --topic T --partitions 6