Kafka Exception InvalidReplicationFactorException
org.apache.kafka.common.errors.InvalidReplicationFactorException
Non-retriable
Admin
InvalidReplicationFactorException is a Kafka exception (org.apache.kafka.common.errors.InvalidReplicationFactorException).
Common Causes
- Replication factor requested exceeds the number of online brokers in the cluster (common in dev/staging with 1-broker clusters trying RF=3)
- Brokers are online but some are in an unclean state and not counted as eligible replicas by the controller
- Topic creation specifying RF=0 or RF=-1 due to misconfigured default.replication.factor or application bug
Solutions
- Match replication factor to the number of available brokers; for single-node dev clusters, set replication-factor=1 explicitly
- Check cluster health with kafka-broker-api-versions.sh or kafka-metadata-quorum.sh to confirm all expected brokers are online and registered
- Set a safe default in server.properties default.replication.factor and enforce RF constraints in your topic provisioning tooling
Example Stack Trace
org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor is below 1 or larger than the number of available brokers.Diagnostic Commands
# Describe topic replicas and ISR status
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic <topic> 2>&1 | grep -E 'ReplicationFactor|Isr|Replicas'
# Count online brokers in the cluster
kafka-broker-api-versions.sh --bootstrap-server localhost:9092 2>&1 | grep -c 'id:'Related
Protocol error: INVALID_REPLICATION_FACTOR (code 38)
Related Admin exceptions: InvalidConfigurationException · InvalidPartitionsException · InvalidTopicException · PolicyViolationException · ThrottlingQuotaExceededException · TopicExistsException · UnsupportedVersionException
Hitting
InvalidReplicationFactorException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.