Quick revision
The short answer
During the bulk load, followers cannot keep up with their leaders, so each one that has not reached the leader's log end within replica.lag.time.max.ms (30 seconds by default) is dropped from the ISR, then re-added when it catches up, over and over. When a partition's ISR falls below min.insync.replicas=2, acks=all writes fail with NotEnoughReplicasException, so the flapping turns into producer errors. We fix it by finding what limits replication (fetcher threads, disk, network, leftover throttles) and giving it more capacity, and by putting a quota on the bulk loader, not by raising replica.lag.time.max.ms.
What to remember
In this answer, we saw that the bulk load pushes followers behind their leaders for longer than replica.lag.time.max.ms, so ISRs shrink and expand repeatedly, and partitions whose ISR falls below min.insync.replicas reject acks=all writes with NotEnoughReplicasException. We traced what limits followers, fetcher threads, disks, network and leftover throttles, fixed the bottleneck, and added a producer quota on the bulk loader, while keeping replica.lag.time.max.ms at a sensible value so real stuck replicas are still detected.
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.
During the bulk load, followers cannot keep up with their leaders, so each one that has not reached the leader's log end within replica.lag.time.max.ms (30 seconds by default) is dropped from the ISR, then re-added when it catches up, over and over. When a partition's ISR falls below min.insync.replicas=2, acks=all writes fail with NotEnoughReplicasException, so the flapping turns into producer errors. We fix it by finding what limits replication (fetcher threads, disk, network, leftover throttles) and giving it more capacity, and by putting a quota on the bulk loader, not by raising replica.lag.time.max.ms.
Why this question is asked
ISR flapping at night is a classic case of two workloads competing for the same brokers: the bulk load wants all the write bandwidth, and replication needs some of it to keep followers in step. If we only look at the producer errors, we may blame the producers; if we only look at the ISR metrics, we may raise a timeout and hide a real problem. Interviewers ask this to see whether we can connect the metrics into one story and pick a fix that addresses the cause. In this answer, we will recap how the ISR is managed, explain the flapping, explain the producer errors, find what limits followers, and choose the fixes.
1A Quick Recap of How the ISR Changes
The in-sync replica set, ISR, is the set of replicas the leader considers caught up. A follower stays in it as long as it reaches the leader's log end offset at least once within replica.lag.time.max.ms, 30 seconds by default in current versions. The rule is about time, not about a number of messages: a follower that keeps fetching but never quite catches up for 30 seconds is removed.
The leader removes a lagging follower by proposing an ISR shrink, which the controller records, and it adds the follower back with an ISR expand as soon as the follower catches up to the log end again. Each change is a metadata update, and the broker counts them in IsrShrinksPerSec and IsrExpandsPerSec. UnderReplicatedPartitions counts partitions whose ISR is smaller than their replica list.
2What the Metrics Are Telling Us
During the day the metrics are quiet, so the cluster has enough capacity for normal traffic. When the bulk load starts, leaders receive data far faster than usual. Followers fetch in a loop, but if they cannot copy data as fast as it arrives, their lag grows, and after 30 seconds without catching up they are removed from the ISR. That is the jump in UnderReplicatedPartitions to about 120 and the spike in IsrShrinksPerSec.
Shrinks and expands spiking together is the signature of flapping rather than of a dead broker. A dead broker causes shrinks and then nothing until it returns. Here followers catch up briefly whenever the load pauses between batches or files, get added back, then fall behind again and are removed. The followers are alive and working; they are just short of capacity for this load.
- Bulk load floods partition leaderswrite rate far above normal
- Followers fall behind the log endreplication capacity is short
- Not caught up for 30 s?YesLeader shrinks the ISRNoFollower stays in the ISR
- ISR below min.insync.replicas=2?Yesacks=all writes rejectedNoWrites continue, less redundancy
- Load pauses, follower catches upISR expands, and the cycle repeats
5 steps in order. Play them, or step through them one at a time.
Shrinks and expands together mean slow but live followers.
3Why Producers Fail With NotEnoughReplicas
min.insync.replicas=2 tells the broker that an acks=all write needs at least two replicas in the ISR, the leader and one follower. With replication factor 3, the ISR can lose one follower and still accept writes. When both followers of a partition are out of the ISR at the same moment, the leader alone is the ISR, and it rejects acks=all produce requests with NOT_ENOUGH_REPLICAS, which the Java client surfaces as NotEnoughReplicasException.
That error is retriable, so producers retry until delivery.timeout.ms runs out. Those that cannot wait that long, or whose ISR stays small for longer, log the exception. So the producer errors are not a separate problem; they are the same replication shortage, reaching the point where Kafka refuses to accept data it cannot protect, which is exactly what min.insync.replicas is for.
4Finding What Limits the Followers
Replication is a pipeline, and we look at each stage. On the follower side, each broker fetches from each other broker using num.replica.fetchers threads, 1 by default. One thread per source broker fetching hundreds of partitions can become the bottleneck long before the disk or network does; the replica fetcher's lag metrics and CPU per thread show it.
Next is disk. Followers write everything they fetch, so the bulk load doubles or triples write traffic across the cluster. If the disks' write throughput or latency is at its limit, followers slow down. Then the network: if brokers sit in different zones, replication crosses zone links, which may be throttled or saturated. Finally, configuration left behind: a partition reassignment sets replication throttles, leader.replication.throttled.rate and follower.replication.throttled.rate plus the throttled replica lists on topics, and if those were not removed afterwards, replication is capped at a low rate forever. kafka-configs.sh --describe on brokers and topics shows them.
5Fixing It
The fix follows the bottleneck. If fetcher threads are the limit, raise num.replica.fetchers, for example to 4, so each broker fetches from each peer in parallel. If disks are the limit, use faster disks or add brokers so the load spreads. If old throttles are present, remove them. If the load simply exceeds what the cluster can replicate, spread it over a longer window.
In almost every case a producer quota on the bulk loader is worth adding. A quota caps how many bytes per second a client may produce; Kafka slows that client down instead of letting it starve replication for everyone else. The load then takes a bit longer, but the ISR stays stable and other producers keep working.
What we should not do is raise replica.lag.time.max.ms to several minutes to make the metrics quiet. The ISR shrinks would stop, but followers would be just as far behind; acks=all latency would grow because the leader waits for slow ISR members, and a replica that is genuinely stuck would stay in the ISR for minutes, eligible to be elected leader while missing data.
6Follow-up questions
Which broker metric shows partitions that are below min.insync.replicas right now?
UnderMinIsrPartitionCount, in the ReplicaManager group of broker metrics, counts the partitions led by that broker whose ISR is smaller than min.insync.replicas. There is also a per-partition UnderMinIsr gauge, and AtMinIsrPartitionCount shows partitions with no spare replica left. Under-min-ISR is the metric that predicts acks=all failures, so it is a better alert than under-replicated partitions alone.
Why not lower min.insync.replicas to 1 during the load?
Because then acks=all writes would be accepted with only the leader holding them, and a leader failure during the load would lose acknowledged data. It removes the errors by removing the protection. If the bulk data is truly re-loadable, a separate topic with its own settings is cleaner than weakening a shared one.
7Conclusion
In this answer, we saw that the bulk load pushes followers behind their leaders for longer than replica.lag.time.max.ms, so ISRs shrink and expand repeatedly, and partitions whose ISR falls below min.insync.replicas reject acks=all writes with NotEnoughReplicasException. We traced what limits followers, fetcher threads, disks, network and leftover throttles, fixed the bottleneck, and added a producer quota on the bulk loader, while keeping replica.lag.time.max.ms at a sensible value so real stuck replicas are still detected.
Open with
What I see is replication not keeping up with the bulk load. A follower stays in the ISR only if it catches up to the leader's log end within replica.lag.time.max.ms, 30 seconds by default.
Then, if they want more
During the load, leaders receive data faster than followers can copy it, so followers are dropped from the ISR, then catch up when the load pauses and are added back. That is why shrinks and expands spike together and about 120 partitions are under-replicated.
When both followers of a partition are out at once, the ISR is just the leader, which is below min.insync.replicas of 2, so acks=all writes are rejected with NotEnoughReplicasException. To fix it I would find what limits followers. num.replica.fetchers defaults to 1, so one thread per source broker may be the bottleneck.
I would also check disk write throughput and latency, the network between zones, and any replication throttles left over from an old reassignment. Then I would fix that: more fetcher threads, faster disks or more brokers, remove stale throttles.
I would also put a producer quota on the bulk loader so it cannot starve replication, and possibly spread the load over a longer window. I would not just raise replica.lag.time.max.ms, because that hides genuinely stuck replicas and keeps them eligible to become leader.
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 "Explain what is happening and how you would fix it.": https://scrivio-interview-library.netlify.app/spring-boot/kafka-internals/9423265a59/