Skip to content
Kafka Is FunProgress

IntermediateInternals

How does Kafka handle leader election when a broker fails?

Reference answer

When a broker fails: 1) The active controller detects the loss via missing heartbeat (ZooKeeper session timeout or KRaft heartbeat). 2) Controller identifies all partitions where the failed broker was leader. 3) For each such partition, controller selects the first broker in the ISR as the new leader. 4) Controller sends LeaderAndIsrRequest to all affected brokers with the new leader info. 5) Brokers update their in-memory routing. 6) Producer metadata becomes stale and refreshes on next request. If the failed broker was the controller, a new controller is first elected via Raft (KRaft) or ZooKeeper.

Expected key concepts: controller, heartbeat, LeaderAndIsrRequest, ISR, new leader, in-memory routing, stale metadata, Raft, KRaft, ZooKeeper