Message Keys and Partitioning Strategies
Learn how Kafka uses message keys to route records to partitions, how this guarantees ordering, and how to design keys and custom partitioners.
The Role of the Key
Every Kafka record can carry an optional key. The key is not just data — it determines which partition the record is written to.
Default Partitioner
When a key is present, the default partitioner hashes it and maps the hash to a partition. The same key always lands in the same partition (for a fixed partition count).
partition = hash(key) % numPartitionsAll lessons in this course
- Producing Messages to Kafka
- Consuming Messages from Kafka
- Understanding Partitions & Offsets
- Message Keys and Partitioning Strategies