Kafka Partition and Replication
Kafka Partition and Replication
Plan partitions, watch key routing, and test replication choices
Route keyed IoT events, then test the partition plan under load and failure.
Follow one message through key hashing, partition selection, leader append, replica sync, and consumer assignment. The same scene shows why hot keys, too few partitions, or weak ISR settings limit a Kafka design.
Partition assignment and replica placement
A keyed message keeps per-device order by landing in one partition. Replicas protect that partition only when enough in-sync copies remain.
Controls
Readouts
Messages with this key keep relative order in partition 2.
Consumer group parallelism is capped by partition count.
The leader handles appends, and followers must stay in sync to be failover candidates.
Partition count, consumer count, and ISR settings are aligned for this scenario.
Model Reading
The selected key is routed with a teaching hash:
Kafka preserves order inside each partition. A topic with many partitions has many ordered logs, not one global order.
Accuracy Notes
- Replication factor counts every copy: one leader plus follower replicas.
- With unclean leader election disabled, a new leader should come from the ISR.
- `acks=all` succeeds only when the ISR size satisfies `min.insync.replicas`.
- Adding consumers beyond partition count creates idle consumers in the same group.
- Changing partition count can change key routes unless a custom partitioning strategy is used.
Guided Checks
- Raise consumers above partitions and note where idle capacity appears.
- Increase key skew and watch one partition become the bottleneck.
- Fail the leader with a lagging follower and compare `acks=1` with `acks=all`.
- Raise partition count and observe that the selected key may move to a different partition.