Lesson 3 of 9 · 26m
Brokers, Replication, Leaders, and What Durability Really Means
Model broker failure correctly: leaders, followers, in-sync replicas, acknowledgements, unclean elections, and the difference between written and committed.
Kafka durability is not a vibe created by having three brokers. It is the interaction of replication factor, leader acknowledgements, min.insync.replicas, client retries, and controller behavior during failure. The worst data-loss incidents usually involve every individual setting looking reasonable in isolation and the combination quietly meaning "we accepted writes on one disk."
Leaders serve, followers replicate
Every partition has one leader replica and zero or more follower replicas. Producers write to the leader; consumers normally fetch from the leader; followers replicate the log:
partition 5, replication.factor=3
broker 1 follower
broker 2 leader <- producer writes here
broker 3 follower
ISR: [2, 3, 1]ISR means in-sync replicas — replicas currently caught up enough to be eligible for safe leadership. A replica can exist on disk and still fall out of ISR when it is too far behind or unreachable.
acks is the client-side durability contract
acks=all
retries=2147483647
max.in.flight.requests.per.connection=5
enable.idempotence=trueacks=0 means the producer does not wait. acks=1 waits for the leader only. acks=all waits for the write to be replicated to all in-sync replicas, subject to min.insync.replicas. If durability matters, acks=1 is usually false confidence: the leader can acknowledge and die before followers copy the record.
min.insync.replicas is the server-side floor
With replication factor three and:
min.insync.replicas=2
acks=alla write succeeds when the leader plus at least one in-sync follower have it. If only the leader remains in ISR, writes fail rather than silently dropping to single-copy durability. That failure is a feature. It forces operators to notice degraded replication instead of discovering loss after a disk failure.
Inspect under-replicated partitions weekly, not during incidents
kafka-topics.sh --bootstrap-server kafka-1:9092 --describe --under-replicated-partitionsAlso watch offline partitions and preferred leader imbalance. Under-replication often starts as a mundane disk, network, or broker-resource problem and becomes data loss only after a second failure.
Unclean leader election is a data-loss tradeoff
unclean.leader.election.enable=falseWhen false, Kafka will not elect a replica outside ISR. This can reduce availability during correlated failures because no sufficiently caught-up replica exists. When true, Kafka may elect a stale replica and permanently lose records that were acknowledged only on the old leader. Choose consciously per topic. A clickstream pipeline and a ledger do not deserve the same answer.
Replication does not replace backup or schema discipline
Kafka replication protects against broker failure, not accidental deletion, poisoned events, bad application migrations, or a producer writing wrong data for a month. For critical streams, know the restore path: mirror data, snapshot downstream state, retain raw inputs, or make reconstruction possible.
Field notes
- Replication factor is configured per topic, not magically inherited in every toolchain; verify created topics.
acks=alldoes not mean all configured replicas — it means all currently in-sync replicas.- Idempotent producers avoid duplicates caused by producer retries within a single producer session; they do not make downstream consumers idempotent.
- Balanced leaders matter. One broker leading most hot partitions becomes the bottleneck even if data is replicated elsewhere.
- Test broker failure before production. Kill a broker, observe ISR, produce, consume, and measure behavior honestly.
Was this lesson helpful?