Scenario 15.1.5 · Dynamic quorum: replace a lost controller
Kafka KRaft dynamic quorum: add and remove controllers
A KRaft voter's machine is lost. A new controller joins as an observer, catches up on the metadata log and is added as a voter (4 voters, majority 3); the dead voter is removed (3 voters, majority 2). Leader elections keep completing throughout.
Run this scenario in the playgroundThree voters, majority 2. t+0.400s
Three KRaft voters run the __cluster_metadata log: c0 is the active controller, c1 and c2 follow. The quorum is dynamic (kraft.version 1), so the voter set itself is a record in that log. With 3 voters a majority is floor(3/2)+1 = 2. O1 is committed to orders-0 (HW 1).
Open at this step: step 1, Three voters, majority 2Voter c2's machine fails. t+1.300s
c2 is killed: its machine is gone and its log stops at offset 1. 2 of 3 voters are still up, which is the majority of 2, so c0 keeps serving. The dead voter still counts toward the quorum size: a voter set never shrinks on its own.
Open at this step: step 2, Voter c2's machine failsElections still complete. t+2.100s
The partition leader broker-1 died at 1500. The controller is serving with 2 of 3 voters, so the election completes: broker-2 becomes leader of orders-0. Meanwhile c0 appended a second metadata record (offset 2) and c1 replicated it.
Open at this step: step 3, Elections still completec3 joins as an observer. t+2.300s
A replacement controller, c3, is formatted with --no-initial-controllers and started. It joins the quorum as an OBSERVER: it fetches __cluster_metadata from the leader but has no vote, so the voters are still c0, c1, c2 and the majority is still 2. c3 starts at offset 0, two records behind the leader.
Open at this step: step 4, c3 joins as an observerToo early: add-controller refused. t+2.600s
kafka-metadata-quorum add-controller is run for c3 before it has caught up. The leader refuses (REQUEST_TIMED_OUT): it adds a voter only once that replica holds the log up to the leader's end offset. Nothing changed. broker-1 has meanwhile restarted and rejoined the ISR.
Open at this step: step 5, Too early: add-controller refusedc3 has caught up. t+3.100s
On the next replication round c3 fetches the records it was missing and reaches offset 2, level with the leader. kafka-metadata-quorum describe --replication now shows it as an Observer with Lag 0.
Open at this step: step 6, c3 has caught upc3 is a voter: 4 voters, majority 3. t+3.400s
add-controller succeeds: c0 commits a VotersRecord that adds c3 (offset 3). The quorum now has 4 voters, so a majority is floor(4/2)+1 = 3. c2 is still dead, so 3 of 4 are up and every live voter is needed: losing one more would freeze the control plane.
Open at this step: step 7, c3 is a voter: 4 voters, majority 3Elections still complete with 4 voters. t+4.200s
broker-2, the leader, died at 3600. c0 still has its majority of 3 (c0, c1, c3), so the election completes and broker-1 leads orders-0. c1 and c3 replicated the VotersRecord at 4000.
Open at this step: step 8, Elections still complete with 4 votersRemove dead c2: 3 voters, majority 2. t+4.700s
kafka-metadata-quorum remove-controller retires c2, which is never coming back. c0 commits a VotersRecord without it (offset 4). The voters are c0, c1, c3: 3 of 3 up, majority 2 again, so one voter can fail without stopping the quorum.
Open at this step: step 9, Remove dead c2: 3 voters, majority 2The new voter set elects. t+5.900s
broker-1 died at 5300. The quorum c0, c1, c3 elects broker-3, the last in-sync replica, as leader of orders-0. The controller kept electing leaders through every step: before the replacement, with 4 voters, and after the removal. Only the majority it needed moved, 2 to 3 and back to 2.
Open at this step: step 10, The new voter set electsWhat you start with
Since Kafka 3.9 (KIP-853) a KRaft quorum can be dynamic: the voter set is stored in the __cluster_metadata log, so controllers are added and removed online with kafka-metadata-quorum add-controller and remove-controller. A new controller first joins as an observer and replicates the log; the leader adds it as a voter only once it has caught up. The majority is always counted over the current voters, floor(voters/2)+1, so it moves with each change.
Step by step
- Three voters, majority 2 t+0.400s Three KRaft voters run the __cluster_metadata log: c0 is the active controller, c1 and c2 follow. The quorum is dynamic (kraft.version 1), so the voter set itself is a record in that log. With 3 voters a majority is floor(3/2)+1 = 2. O1 is committed to orders-0 (HW 1). Open at this step: step 1, Three voters, majority 2
- Voter c2's machine fails t+1.300s c2 is killed: its machine is gone and its log stops at offset 1. 2 of 3 voters are still up, which is the majority of 2, so c0 keeps serving. The dead voter still counts toward the quorum size: a voter set never shrinks on its own. Open at this step: step 2, Voter c2's machine fails
- Elections still complete t+2.100s The partition leader broker-1 died at 1500. The controller is serving with 2 of 3 voters, so the election completes: broker-2 becomes leader of orders-0. Meanwhile c0 appended a second metadata record (offset 2) and c1 replicated it. Open at this step: step 3, Elections still complete
- c3 joins as an observer t+2.300s A replacement controller, c3, is formatted with --no-initial-controllers and started. It joins the quorum as an OBSERVER: it fetches __cluster_metadata from the leader but has no vote, so the voters are still c0, c1, c2 and the majority is still 2. c3 starts at offset 0, two records behind the leader. Open at this step: step 4, c3 joins as an observer
- Too early: add-controller refused t+2.600s kafka-metadata-quorum add-controller is run for c3 before it has caught up. The leader refuses (REQUEST_TIMED_OUT): it adds a voter only once that replica holds the log up to the leader's end offset. Nothing changed. broker-1 has meanwhile restarted and rejoined the ISR. Open at this step: step 5, Too early: add-controller refused
- c3 has caught up t+3.100s On the next replication round c3 fetches the records it was missing and reaches offset 2, level with the leader. kafka-metadata-quorum describe --replication now shows it as an Observer with Lag 0. Open at this step: step 6, c3 has caught up
- c3 is a voter: 4 voters, majority 3 t+3.400s add-controller succeeds: c0 commits a VotersRecord that adds c3 (offset 3). The quorum now has 4 voters, so a majority is floor(4/2)+1 = 3. c2 is still dead, so 3 of 4 are up and every live voter is needed: losing one more would freeze the control plane. Open at this step: step 7, c3 is a voter: 4 voters, majority 3
- Elections still complete with 4 voters t+4.200s broker-2, the leader, died at 3600. c0 still has its majority of 3 (c0, c1, c3), so the election completes and broker-1 leads orders-0. c1 and c3 replicated the VotersRecord at 4000. Open at this step: step 8, Elections still complete with 4 voters
- Remove dead c2: 3 voters, majority 2 t+4.700s kafka-metadata-quorum remove-controller retires c2, which is never coming back. c0 commits a VotersRecord without it (offset 4). The voters are c0, c1, c3: 3 of 3 up, majority 2 again, so one voter can fail without stopping the quorum. Open at this step: step 9, Remove dead c2: 3 voters, majority 2
- The new voter set elects t+5.900s broker-1 died at 5300. The quorum c0, c1, c3 elects broker-3, the last in-sync replica, as leader of orders-0. The controller kept electing leaders through every step: before the replacement, with 4 voters, and after the removal. Only the majority it needed moved, 2 to 3 and back to 2. Open at this step: step 10, The new voter set elects
The takeaway
Replacing a controller is two committed changes, not a config edit and a rolling restart: add the caught-up observer as a voter, then remove the dead one. In between, the quorum had 4 voters and needed 3 of them, one more than before, which is why the dead voter should not be left in the set. The simulator commits each VotersRecord at once and does not model directory ids; real Kafka identifies a voter by node id and directory id, and remove-controller needs both.
Embed this scenario
Paste this into a blog post, a course page or your team's docs. The scenario plays inside your page, and the link under it points readers to this walkthrough.
<iframe src="https://monedula.dev/kafka-simulator/embed/?scenario=15.1.5" title="Kafka Simulator: Dynamic quorum: replace a lost controller" width="100%" height="520" style="border:1px solid #d0d0d0;border-radius:8px" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
<p><a href="https://monedula.dev/kafka-simulator/scenarios/dynamic-quorum/">Kafka KRaft dynamic quorum: add and remove controllers</a></p>