Fixing under-replicated partitions in Kafka
Codemia Knowledge Hub ·
A Kafka partition is under-replicated when one or more of its replicas is not in sync with the leader, which weakens fault tolerance and availability. Find affected partitions with kafka-topics.sh --describe --under-replicated-partitions, then fix the cause: a failed broker, network trouble, overloaded brokers or replication misconfiguration.
What causes under-replicated partitions
- Broker failures: when a broker goes down, the partitions it hosted as leader or replica may stay under-replicated until the broker is restored or replacements are fully replicated.
- Network issues: poor connectivity between brokers delays or breaks replication.
- High load: overloaded brokers replicate slowly, causing replication lag.
- Configuration errors: incorrect replication settings, including improper values for
replication.factorandmin.insync.replicas.
Finding under-replicated partitions
Kafka's kafka-topics.sh script lists them:
The output shows each under-replicated partition with its topic name, partition number, leader broker, replicas and in-sync replicas.
How to fix them
1. Make sure all brokers are available
Check that every broker is up. Restart failed brokers and read the broker logs to find problems such as hardware failures, configuration mistakes or JVM issues.
2. Balance broker load
Spreading load evenly across brokers reduces under-replication caused by high load. Tools like LinkedIn’s Cruise Control can automate Kafka load balancing.
3. Adjust replication settings
Increasing min.insync.replicas can sometimes lead to under-replication if continuous replication to the required number of replicas is not feasible. Depending on your durability and fault tolerance requirements, you may need to adjust this value or the topic's replication factor.
4. Monitor network health
Regularly auditing connectivity and throughput between brokers can head off under-replication caused by network glitches.
5. Use the administrative tools
kafka-reassign-partitions.sh can manually trigger replication or reassign partitions to different brokers.
Example: the user_logs topic
Suppose the topic "user_logs" suddenly shows under-replicated partitions. Typical steps:
Causes, fixes and tools
| Issue | Solution | Tools/Commands Used |
| Broker Failures | Restart and fix brokers | systemctl restart, jps, Broker logs |
| Network Issues | Verify and improve network settings | nc, Network logs |
| High Load | Rebalance or increase resources | Cruise Control, kafka-reassign-partitions.sh |
| Configuration Errors | Adjust replication.factor, min.insync.replicas | Kafka config files |
Preventing it next time
- Automate detection: scripts that regularly check for under-replicated partitions and trigger alerts or corrective actions make the cluster more resilient.
- Back up data: regular backups of Kafka data protect against data loss in severe failures, on top of replication.
- Train the team: keeping the people who run Kafka current on best practices and new tools prevents many under-replication issues.
Related reading
- Flask + RabbitMQ + SocketIO - forwarding messages
- Flask API as real time kafka consumer
- Flink Kafka connector - commit offset without checkpointing
- flink kafka consumer groupId not working
- FLP Impossiblity Result assumption of C_1 = e'(C_0)
- Flush CoreDNS Cache on Kubernetes Cluster
- Fixing Xcode 9 issue iPhone is busy Preparing debugger support for iPhone
- Flannel and docker don't start
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.