Kafka Replication & Leader Election
Software Engineer path · lesson 82 of 99Production Kafka fault tolerance: replicate a partition across brokers, commit with acks=all, and watch the controller elect a new leader from the ISR when a broker crashes.
Broker 1
LeaderBroker 2
FollowerBroker 3
FollowerKey insight
With acks=all, a record (green) is only committed once every in-sync replica has copied it — so when the leader dies, the controller can elect any ISR member and no acknowledged data is lost. Replication factor 3 tolerates 1 broker failure and keeps writes flowing — min.insync.replicas=2 is satisfied (with min.insync.replicas=2).
A write with acks=all
Order what happens between send and acknowledgement.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
- 1Drop a step here
- 2Drop a step here
- 3Drop a step here
- 4Drop a step here
- 5Drop a step here
Test your knowledge
Under acks=all, when is a produced record considered committed?
The short version
A replicated partition is like a document with one author (the leader) and proofreaders (followers) keeping live copies. If the author quits, a proofreader who has every page so far takes over — nothing already published is lost.
In more depth
Kafka Replication & ISR
Kafka replicates every partition across replication.factor brokers. One replica is the leader (serves all reads/writes); the rest are followers that fetch from the leader.
In-Sync Replicas (ISR)
The ISR is the set of replicas fully caught up with the leader. With acks=all a record is only committed (advancing the high-water mark) once every ISR member has copied it — so an elected leader never loses acknowledged data.
Failover
When the leader crashes, the KRaft controller elects the first eligible in-sync replica as the new leader. unclean.leader.election=false ensures only ISR members are eligible, trading availability for durability.
Interview Questions
References & Further Reading
Related topics
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required