Publishing: key, partition, leader
Each topic is split into partitions spread over brokers, and each partition is an append-only log with one leader. The client library caches which broker leads each partition, hashes the key to choose one, and sends compressed batches to its leader.
- The orders service hashes the key, order 42, to pick a partition, so every event for that order lands in the same one.
- It looks up that partition’s leader in its cached metadata and sends a batch there.
- The leader appends the batch to its log, and each record gets the next offset.
- The leader answers with the offsets; the deep dive on durability says when that answer is safe.
Diagram as text
Components: Partition 0 leader (Queue); Orders service (Service); Partition 1 leader (Queue); Cached metadata (Cache); Partition 2 leader (Queue). Connections: Orders service → Partition 1 leader (order 42: a batch); Orders service → Partition 0 leader (other keys); Orders service → Partition 2 leader (other keys); Orders service → Cached metadata (who leads?).
Read:Learn: High-level architectureLearn: Apache Kafka
Check yourself
Why hash the key rather than spread records round-robin?
Show answerHide answer
Records with the same key then land in one partition, which is the only place order holds. Spreading records evenly balances load but loses order per key.