Kafka NotEnoughReplicasException in a rolling restart: RF and min.insync.replicas math
A routine rolling restart made producers fail with NotEnoughReplicasException. Some topics had replication factor 2 with min.insync.replicas 2, and the restart moved on before followers rejoined the ISR. The math, the fix and a safer restart gate.
During a planned rolling restart to apply a JVM patch, the payments-events producers started failing. For about 11 minutes, roughly a third of produce requests were rejected, the payment service's outbox backed up, and an alert fired on "producer record-error-rate > 0". Nothing else in the cluster looked broken: all three brokers were up again within minutes of each restart.
org.apache.kafka.common.errors.NotEnoughReplicasException: Messages are rejected since there are fewer in-sync replicas than required.
Some time later, records that could not be delivered expired on the producer:
org.apache.kafka.common.errors.TimeoutException: Expiring 37 record(s) for payments-events-4:120001 ms has passed since batch creation
Reproducing it
On a three-broker test cluster:
kafka-topics.sh --bootstrap-server broker1:9092 --create --topic repro \
--partitions 6 --replication-factor 2 --config min.insync.replicas=2
Produce with acks=all, then stop one broker. Every partition that had a replica on the stopped broker immediately starts rejecting writes with NotEnoughReplicasException.
What we ruled out
Broker crash or disk issue. Each broker restarted cleanly; logs showed normal shutdown and startup.
Producer misconfiguration. The producer used
acks=allandenable.idempotence=true, which is what we want for payment events.Network partition. Inter-broker replication metrics were normal before and after each restart.
Root cause
Two things combined:
Replication factor 2 with
min.insync.replicas=2.payments-eventshad been created by an old script with--replication-factor 2, while the cluster defaultmin.insync.replicaswas 2. With RF 2 and min ISR 2, losing any single replica makes the partition unwritable foracks=allproducers. A rolling restart always takes one replica offline.The restart script did not wait for the ISR to recover. It restarted the next broker as soon as the previous one reported "started", not when its replicas had caught up and rejoined the ISR. For a few partitions with RF 3, two replicas were briefly out of the ISR at the same time, so even those dropped below min ISR.
What is happening under the hood
Each partition has a leader and followers. The in-sync replica set (ISR) is the leader plus followers that are fully caught up (a follower falls out of the ISR if it has not caught up within replica.lag.time.max.ms, 30 seconds by default).
With acks=all, the leader only acknowledges a write once every replica currently in the ISR has it. On its own, that could mean "the leader alone" if all followers have dropped out. min.insync.replicas puts a floor under it: if the ISR is smaller than this number, the leader rejects acks=all writes with NotEnoughReplicas. This is a deliberate choice of consistency over availability.
The math that matters:
RF | min.insync.replicas | Replicas you can lose and still write (acks=all) | Replicas you can lose without data loss risk |
|---|---|---|---|
1 | 1 | 0 | 0 |
2 | 1 | 1 | 0 (one copy left while writing) |
2 | 2 | 0 | 1 |
3 | 2 | 1 | 1 (two copies always confirmed) |
3 | 3 | 0 | 2 |
5 | 3 | 2 | 2 |
The common production choice is RF 3, min ISR 2, acks=all: one broker can be down for maintenance and writes still succeed with two confirmed copies.
Consumers are not affected by min ISR; reads continue from the leader. Producers using acks=1 or acks=0 are not blocked either, but they risk losing acknowledged data on leader failover, which we covered in post 437. Background on leaders, followers and ISR is in post 252.
Environment
Component | Version / value |
|---|---|
Apache Kafka | 3.9.0, KRaft mode, 3 brokers, 3 controllers |
Producer | Java client 3.9.0, |
| 24 partitions, RF 2, |
Other topics | RF 3, |
| 120000 (default) |
Restart tooling | Ansible play, |
Finding affected topics
List partitions that are currently below min ISR, and those under-replicated:
kafka-topics.sh --bootstrap-server broker1:9092 --describe --under-min-isr-partitions
kafka-topics.sh --bootstrap-server broker1:9092 --describe --under-replicated-partitions
Find topics whose RF is not greater than their min ISR (the dangerous combination):
kafka-topics.sh --bootstrap-server broker1:9092 --describe \
| awk '/ReplicationFactor/ {
t=$2; rf=0; mi=""
for (i=1;i<=NF;i++) { if ($i=="ReplicationFactor:") rf=$(i+1); if ($i ~ /min.insync.replicas=/) { split($i,a,"="); mi=a[2] } }
if (mi=="") mi=2 # cluster default here; adjust
if (rf+0 <= mi+0) print t, "RF=" rf, "minISR=" mi
}'
That printed payments-events RF=2 minISR=2 and two other small topics.
Who is affected
Any topic where RF is equal to
min.insync.replicasand producers useacks=all(the default since Kafka 3.0, because idempotence is on by default).Clusters with fewer brokers than RF + 1, where maintenance cannot keep a full ISR.
Rolling restart tools that do not wait for under-replicated partitions to return to zero.
This is a paid story
Subscribe to read the full content, access all paid stories, and support the authors.
Add a label
Embed this post
<iframe src="https://www.hibug.me/kafka-notenoughreplicas-min-insync-replicas" width="700" height="420" frameborder="0" loading="lazy"></iframe>
I started as a Linux administrator in a hosting company and never really left the command line. Today I look after fleets of Linux servers, edge networking and CDN setups for web platforms, and I still do on-call shifts. My posts are the notes I wish I had found at three in the morning: the symptom, the commands that narrowed it down, the actual cause and the change that fixed it. I try to explain what each number in vmstat, iostat or ss output means, so you can reason about your own system instead of copying commands.
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.