Kafka Exception NotEnoughReplicasException
org.apache.kafka.common.errors.NotEnoughReplicasException
Retriable
Broker
Number of insync replicas for the partition is lower than min.insync.replicas
Common Causes
- One or more brokers are down, shrinking the ISR below 'min.insync.replicas' (common during broker maintenance or unplanned failures)
- Slow replica brokers falling out of ISR due to disk I/O bottleneck causing replica fetch lag to exceed 'replica.lag.time.max.ms'
- Cluster scaled down (broker decommissioned) without first reassigning partitions, leaving some partitions under-replicated
Solutions
- Short-term: temporarily reduce 'min.insync.replicas' on the affected topic to allow writes to proceed during the incident (acknowledge this reduces durability guarantees)
- Restore the downed broker or add a replacement broker and use kafka-reassign-partitions.sh to rebalance partitions back to full replication
- Monitor ISR size proactively: alert when 'UnderReplicatedPartitions' JMX metric > 0 for more than 60 seconds to catch degradation before min.insync.replicas is breached
Example Stack Trace
org.apache.kafka.common.errors.NotEnoughReplicasException: Messages are rejected since there are fewer in-sync replicas than required.Diagnostic Commands
# Check for under-replicated partitions
kafka-topics.sh --describe --bootstrap-server localhost:9092 --under-replicated-partitions
# Check for unavailable partitions
kafka-topics.sh --describe --bootstrap-server localhost:9092 --unavailable-partitionsRelated
Protocol error: NOT_ENOUGH_REPLICAS (code 19)
Related Broker exceptions: CorruptRecordException · FencedLeaderEpochException · LeaderNotAvailableException · NetworkException · NotEnoughReplicasAfterAppendException · NotLeaderOrFollowerException · TimeoutException · UnknownLeaderEpochException
Hitting
NotEnoughReplicasException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.