0Pricing
Apache Kafka & Stream Processing Fundamentals · Lesson

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) % numPartitions

All lessons in this course

  1. Producing Messages to Kafka
  2. Consuming Messages from Kafka
  3. Understanding Partitions & Offsets
  4. Message Keys and Partitioning Strategies
← Back to Apache Kafka & Stream Processing Fundamentals