Quick revision
The short answer
A broker whose process is up is not yet back in the ISR: it must recover its logs and fetch what it missed, so restarting the next broker earlier left partitions with replicas on both brokers at one in-sync replica, below min.insync.replicas=2, or none, which made them offline. The safe procedure gates every step on the broker being registered and unfenced, UnderReplicatedPartitions back to 0, and kafka-topics.sh --describe with --under-min-isr-partitions and --unavailable-partitions returning nothing, uses controlled shutdown with enough time, restarts controllers separately while checking the quorum, and builds these checks into the automation so it stops itself when a check fails.
What to remember
In this answer, we saw that a broker whose process is running is not yet an in-sync replica, so the script restarted the next broker while partitions still depended on the first, dropping them below min.insync.replicas or to no leader at all. A safe restart gates every step on registration, UnderReplicatedPartitions at 0 and no under-min-ISR or unavailable partitions, uses controlled shutdown with time to finish, rolls controllers separately while checking the quorum, and puts these checks into the automation so it stops itself.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A broker whose process is up is not yet back in the ISR: it must recover its logs and fetch what it missed, so restarting the next broker earlier left partitions with replicas on both brokers at one in-sync replica, below min.insync.replicas=2, or none, which made them offline. The safe procedure gates every step on the broker being registered and unfenced, UnderReplicatedPartitions back to 0, and kafka-topics.sh --describe with --under-min-isr-partitions and --unavailable-partitions returning nothing, uses controlled shutdown with enough time, restarts controllers separately while checking the quorum, and builds these checks into the automation so it stops itself when a check fails.
Why this question is asked
Rolling restarts are routine, and that is what makes them dangerous: an automation script that works on a quiet cluster can take partitions offline on a busy one. The script here used the wrong signal for readiness, a running process. Interviewers ask this to see whether we know what a broker goes through after a restart and what really proves it is safe to continue. In this answer, we will recap the stages of a broker coming back, reconstruct what went wrong, define the gates that make a restart safe, look at controlled shutdown and controllers, and turn it all into automation.
1A Quick Recap: What 'Up' Really Means
When a broker restarts, it passes through several stages. First the process starts. Then, if it was not shut down cleanly, it recovers its logs, checking and rebuilding index files. It registers with the controllers, which unfence it, meaning it may again lead partitions and serve clients. Finally its follower replicas fetch everything that was written while it was down, and only when each one has caught up does the leader add it back to the ISR, the set of in-sync replicas.
On a busy cluster, the gap between the first stage and the last can be minutes, sometimes much longer after an unclean stop. Throughout that gap the process is up, its port answers, and a simple health check is green. But for every partition it hosts, it does not yet count as an in-sync copy.
2What Went Wrong
Take a partition with replicas on brokers 2, 3 and 7, replication factor 3 and min.insync.replicas=2. The script restarted broker 2. While broker 2 was still catching up, the ISR was {3, 7}: two copies, still enough for acks=all. The script saw broker 2's process running and restarted broker 3. Now the ISR shrank to {7}, one copy, below min.insync.replicas, so producers with acks=all got NotEnoughReplicasException. For a partition whose replicas were on 2, 3 and 9 and whose third replica was already lagging, the ISR became empty and the partition had no eligible leader: offline.
| Moment | ISR | acks=all producers |
|---|---|---|
| Before | {2, 3, 7} | OK |
| Broker 2 restarting | {3, 7} | OK (2 >= min ISR) |
| Broker 2 process up, still catching up | {3, 7} | OK |
| Script restarts broker 3 | {7} | NotEnoughReplicasException |
| Partition with a lagging third replica | {} | Offline, no leader |
Notice that nothing failed in the usual sense. Each broker restarted correctly. The outage came only from the timing: the script removed a second copy before the first had come back.
3The Gates That Make a Restart Safe
Each step must wait until the cluster has fully recovered from the previous one. Concretely, before restarting the next broker we require that the restarted broker is registered and unfenced, that UnderReplicatedPartitions is back to 0 across the cluster, and that no partition is under min ISR or unavailable. The topic tool checks the last two directly.
In practice we add a timeout that stops the roll and alerts a human if the cluster does not recover within, say, 30 minutes. After the last broker, preferred leader election, automatic by default or triggered with kafka-leader-election.sh, moves leadership back to the preferred replicas so load is balanced again.
4Controlled Shutdown and Its Time Budget
A normal SIGTERM triggers controlled shutdown: the broker asks the controller to move leadership of its partitions to other in-sync replicas, then flushes and closes its logs cleanly. Clients see a quick leader change, and on restart the broker skips log recovery because its logs were closed cleanly.
This needs time. If the service manager kills the process too soon, for example systemd's default stop timeout or a short Kubernetes terminationGracePeriodSeconds, the broker dies uncleanly: leadership moves only when the controller notices the missing broker, clients see errors meanwhile, and on start the broker recovers every log segment that was open, which can take many minutes. So we give the stop a generous budget, often several minutes, and check the broker log for a clean shutdown before starting the new process.
5Controllers Are Restarted Separately
The 3 KRaft controllers form a quorum that needs a majority, 2 of 3, to make any metadata change. Restarting two at once would stop leader elections, so a broker failure at that moment could not be handled. We therefore roll controllers on their own, one at a time, and between them check that the quorum has a leader and that the restarted controller has caught up.
Only when every voter shows a lag of 0 do we move to the next controller. Brokers appear in the same output as observers, which is another quick way to confirm a restarted broker is following the metadata log again.
6Putting the Checks Into the Automation
A runbook that depends on a person remembering to check is the same script with a slower failure. The checks belong in the automation: a Kubernetes operator that understands Kafka readiness, or a script that reads metrics and the topic tool before every step and stops automatically when a check fails.
- All partitions healthy?YesRestart the next brokerNoStop and alert
- SIGTERM, wait for controlled shutdowngenerous stop timeout
- Start; registered and unfenced?YesWait for catch-upNoStop and alert after timeout
- URP, under-min-ISR, unavailable all 0?YesNext brokerNoKeep waiting until timeout
- After the last brokerpreferred leader election
5 steps in order. Play them, or step through them one at a time.
Every step proves the previous one finished before moving on.
7Follow-up questions
Why not check only that the broker's port answers?
Because the port answers as soon as the process starts, long before the broker has recovered its logs and caught up its replicas. Port checks prove liveness, not that the cluster has its copies back.
How long should the gate wait before giving up?
Long enough for a normal catch-up on our busiest broker, measured in staging or past restarts, plus margin. If recovery takes longer, something is wrong, and stopping for a human is better than continuing the roll.
Would min.insync.replicas=1 have avoided the errors?
It would have avoided NotEnoughReplicasException, but by accepting writes with a single copy, which can lose acknowledged data if that broker fails. The fix is to restart safely, not to lower durability.
8Conclusion
In this answer, we saw that a broker whose process is running is not yet an in-sync replica, so the script restarted the next broker while partitions still depended on the first, dropping them below min.insync.replicas or to no leader at all. A safe restart gates every step on registration, UnderReplicatedPartitions at 0 and no under-min-ISR or unavailable partitions, uses controlled shutdown with time to finish, rolls controllers separately while checking the quorum, and puts these checks into the automation so it stops itself.
Open with
The script used the wrong readiness signal. A broker whose process is up is not back in the ISR yet: it may be recovering logs, and its followers still have to fetch what they missed.
Then, if they want more
So when the script restarted the next broker, partitions with replicas on both brokers dropped to one in-sync replica, below min.insync.replicas of two, so acks=all producers got NotEnoughReplicas, and partitions whose third replica was already lagging had none and went offline. The safe procedure gates each step.
The restarted broker must be registered and unfenced, UnderReplicatedPartitions must be back to zero, and kafka-topics describe with under-min-isr-partitions and unavailable-partitions must return nothing. Only then the next broker. I would use controlled shutdown, which a normal SIGTERM triggers, and give it enough time before any forced kill, because a killed broker needs log recovery and a longer catch-up.
After the last broker, preferred leader election rebalances leadership. Controllers are restarted separately, one at a time, checking kafka-metadata-quorum describe status and replication so the quorum keeps a majority and the restarted one catches up.
Finally I would put all of that into the automation, an operator or a script that reads these checks before each step, with a timeout that stops the roll and alerts a person if anything does not recover.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Halfway through, producers using acks=all on topics with min.insync.replicas=2 log...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-operations/fd4701d6ed/