What if a replica falls behind?
Solution and explanation
What happens
A follower that has not caught up with the leader's log end for longer than replica.lag.time.max.ms (default 30 s) is **removed from the ISR**. It keeps fetching and replicating; once it catches up, the leader adds it back.
Causes
- Broker overloaded (CPU, disk I/O saturation, too many partitions).
- Slow or failing disk, network congestion between brokers or availability zones.
- Long garbage collection pauses.
- Broker restarting and catching up after downtime.
- Under-sized
num.replica.fetchersfor a high partition count.
Effects
- The partition is **under-replicated**: fewer copies of new data.
- With
acks=all, the producer now needs only the remaining ISR members, so writes continue as long as ISR ≥min.insync.replicas. - If ISR drops below
min.insync.replicas,acks=allwrites fail withNotEnoughReplicasException. - The lagging replica **cannot become leader** (with clean leader election), so if the leader also fails and no other ISR member exists, the partition goes offline.
Detection
- Metric
UnderReplicatedPartitions> 0 andIsrShrinksPerSec/IsrExpandsPerSec. kafka-topics.sh --describe --under-replicated-partitions.- Replica fetcher lag metrics (
ReplicaFetcherManager MaxLag).
Fixes
- Find the slow broker (disk latency, CPU, network) and fix or replace it.
- Rebalance partition leadership and replicas across brokers (Cruise Control).
- Increase
num.replica.fetchers, add brokers, reduce partitions per broker. - Throttle reassignments so recovery does not overload the cluster.
Summary
A lagging follower is removed from the ISR (reducing redundancy and possibly blocking acks=all writes), keeps replicating, and rejoins once caught up; monitor under-replicated partitions and fix the slow broker.
