Kafka
Data Replication
Partitions
Data Management
Troubleshooting

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

  1. 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.
  2. Network issues: poor connectivity between brokers delays or breaks replication.
  3. High load: overloaded brokers replicate slowly, causing replication lag.
  4. Configuration errors: incorrect replication settings, including improper values for replication.factor and min.insync.replicas.

Finding under-replicated partitions

Kafka's kafka-topics.sh script lists them:

bash
kafka-topics.sh --bootstrap-server localhost:9092 --describe --under-replicated-partitions

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:

bash
1# First, check the status of the topic
2kafka-topics.sh --bootstrap-server localhost:9092 --topic user_logs --describe
3
4# If there are under-replicated partitions, check the health of the brokers
5jps # Java process status to check if Kafka brokers are running
6nc -vz broker_ip 9092 # Check network connection to the broker
7
8# Restart any failing brokers and monitor logs for any recurrent issues
9systemctl restart kafka-broker # Assuming systemd management
10tail -f /var/log/kafka/server.log # Watch logs

Causes, fixes and tools

IssueSolutionTools/Commands Used
Broker FailuresRestart and fix brokerssystemctl restart, jps, Broker logs
Network IssuesVerify and improve network settingsnc, Network logs
High LoadRebalance or increase resourcesCruise Control, kafka-reassign-partitions.sh
Configuration ErrorsAdjust replication.factor, min.insync.replicasKafka 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.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design