Kafka Partition and Replication
Plan partitions, watch key routing, and test replication choices
animation
kafka
stream-processing
distributed-systems
Kafka
Partition Planning
Replication
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.
Key route
sensor-17 -> P2
Hot partition
P2 has 34% load
Consumer lanes
4 active, 0 idle
Write state
Available
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.
Hash route
Model Reading
The selected key is routed with a teaching hash:
partition = stableHash(key) % partition_count
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.