Monedula

Kafka troubleshooting

NotEnoughReplicasException (NOT_ENOUGH_REPLICAS)

Kafka error · NOT_ENOUGH_REPLICAS · retriable

org.apache.kafka.common.errors.NotEnoughReplicasException

The partition has fewer in-sync replicas than its min.insync.replicas, so the leader refuses acks=all writes instead of acknowledging data that too few brokers hold. Bring the missing replicas back into the ISR; lower min.insync.replicas only as a deliberate durability trade-off.

Reproduce it in the playground

The moment it happensacks=all produce blocked - NotEnoughReplicas. t+9.200s

Durability wins: acks=all refuses to ack below min.insync.replicas.

Open at this step: step 4, acks=all produce blocked - NotEnoughReplicas

What it means

With acks=all a write succeeds only once every replica in the in-sync replica set (ISR) has it, and the topic setting min.insync.replicas is the smallest ISR the leader accepts such a write with. The leader checks the ISR size before it appends: below the minimum it rejects the batch with NOT_ENOUGH_REPLICAS (error code 19) and writes nothing. The broker message gives the numbers, for example "The size of the current ISR : 1 is insufficient to satisfy the min.isr requirement of 2 for partition orders-0, ...". NotEnoughReplicasException extends RetriableException, so the producer logs a warning per attempt ("Got error produce response ... retrying ... Error: NOT_ENOUGH_REPLICAS") and retries with backoff until delivery.timeout.ms (default 2 minutes) runs out. Only then does the send fail, with this exception or with a TimeoutException ("Expiring N record(s)") if the batch expired while waiting for its next attempt. A relative, NOT_ENOUGH_REPLICAS_AFTER_APPEND (code 20), means the ISR shrank after the leader had already appended the batch, so a retry from a non-idempotent producer can write a duplicate. Writes with acks=0 or acks=1 are not checked against min.insync.replicas.

Likely causes, most common first

  1. A broker is down or a follower fell behind. A follower that has not caught up to the leader's log end within replica.lag.time.max.ms (default 30 seconds) is removed from the ISR, and a stopped broker leaves every ISR it was in. With replication factor 3 and min.insync.replicas 2, one missing replica is tolerated; a second one blocks acks=all writes on that partition.
  2. Several replicas failed together. Brokers that share a rack, power feed or availability zone fail as a unit. If too many of a partition's replicas share one failure domain, a single outage takes the ISR below the minimum: with replication factor 4 split over two racks and min.insync.replicas 3, losing either rack is enough.
  3. min.insync.replicas leaves no headroom. With replication factor 3 and min.insync.replicas 3, any single replica restart, including a routine rolling restart, blocks acks=all writes. The same happens when someone raises the minimum on a live topic with kafka-configs.sh; topic configs change without a broker restart.
  4. The topic has fewer replicas than the minimum. A topic whose replication factor is below min.insync.replicas can never take an acks=all write, and one whose replication factor equals it fails on the first lost replica. Check topics auto-created with a low default.replication.factor against a broker-wide minimum of 2.

How to fix it

What not to do

Does the client retry it?

Yes. The Kafka client treats this error as retriable and retries the request until delivery.timeout.ms runs out.

Configs involved

Reproduce it in the simulator

Sources

Related

All troubleshooting pages