Data Engineering Bug Report Paid

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.

Kenji Watanabe Kenji Watanabe @kenjiwatanabe · December 02, 2026 · 7 min read · 102 Views
653-kafka-notenoughreplicas-min-insync-replicas

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=all and enable.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:

  1. Replication factor 2 with min.insync.replicas=2. payments-events had been created by an old script with --replication-factor 2, while the cluster default min.insync.replicas was 2. With RF 2 and min ISR 2, losing any single replica makes the partition unwritable for acks=all producers. A rolling restart always takes one replica offline.

  2. 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, acks=all, enable.idempotence=true

payments-events

24 partitions, RF 2, min.insync.replicas=2 (inherited)

Other topics

RF 3, min.insync.replicas=2

delivery.timeout.ms

120000 (default)

Restart tooling

Ansible play, serial: 1, wait on port 9092 only

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.replicas and producers use acks=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

#replication #kafka #min-insync-replicas #acks #rolling-restart
Written by
Kenji Watanabe @kenjiwatanabe

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.

Advertisement

Comments

0

No comments yet. Be the first to comment!

Sign In to post a comment.