Troubleshooting Kafka: Common Problems, Diagnosis Steps and Fixes
A General Method
- What changed? Deployment, config change, traffic spike, certificate expiry, network change, broker restart
- Scope: one client, one topic, one broker or the whole cluster?
- Check cluster health: controller, offline and under-replicated partitions, broker logs, disk space
- Check the client: error messages, client logs with timestamps, client metrics
- Mitigate first, fix root cause later: restart a stuck consumer, move traffic, free disk, throttle a noisy client
- Write down timeline and cause for the post-incident review
First Commands
bash
bin/kafka-metadata-quorum.sh --bootstrap-server $BS describe --status # controller quorum
bin/kafka-topics.sh --bootstrap-server $BS --describe --under-replicated-partitions
bin/kafka-topics.sh --bootstrap-server $BS --describe --unavailable-partitions
bin/kafka-consumer-groups.sh --bootstrap-server $BS --describe --group my-group --state
df -h /var/lib/kafka ; free -m ; iostat -x 1 3 ; ss -tnlp | grep 9092
sudo journalctl -u kafka --since "30 min ago" | grep -E "ERROR|WARN" | tail -50
Problem 1: Client Cannot Connect or Times Out
| Symptom | Cause | Fix |
|---|---|---|
Bootstrap connection works, then Connection to node 1 (localhost/127.0.0.1:9092) could not be established | Broker advertises an address clients cannot reach (advertised.listeners=localhost) | Set advertised.listeners to a real hostname or IP reachable from clients. In Docker or Kubernetes use separate internal and external listeners |
TimeoutException: Topic not present in metadata | Topic missing (auto-create disabled), wrong name, ACL denies Describe, or no connectivity | Create the topic, check name and ACLs |
UnknownHostException | DNS cannot resolve the advertised hostname | Fix DNS or /etc/hosts on clients |
| TLS errors | Certificate, SAN, truststore problems | See the security lesson |
| Works from one network only | Firewall, security groups, load balancer between client and broker | Open broker ports to the client subnet. Do not place a plain TCP load balancer in front of individual brokers without per-broker listeners |
text
# Kubernetes / Docker pattern with two listeners
listeners=INTERNAL://:9092,EXTERNAL://:9094
advertised.listeners=INTERNAL://kafka-0.kafka.svc:9092,EXTERNAL://kafka-0.public.example.com:9094
listener.security.protocol.map=INTERNAL:SASL_SSL,EXTERNAL:SASL_SSL,CONTROLLER:SASL_SSL
inter.broker.listener.name=INTERNAL
Problem 2: Producer Errors
| Error | Cause | Fix |
|---|---|---|
NotEnoughReplicasException / NotEnoughReplicasAfterAppendException | ISR smaller than min.insync.replicas | Find the failed or slow broker, restore ISR. Do not lower min.insync.replicas as a quick fix for important data |
TimeoutException: Expiring N record(s) ... delivery timeout | Broker slow or unreachable, leader election, buffer too small | Check broker health, network, increase delivery.timeout.ms only if needed |
RecordTooLargeException | Message above limits | Reduce size, or raise max.request.size (producer), message.max.bytes (broker/topic) and fetch limits for consumers consistently |
TopicAuthorizationException | Missing ACL | Add Write and Describe ACLs |
OutOfOrderSequenceException | Broker lost producer state (retention of transactional/idempotent state, or unclean election) | Check for unclean leader election and data loss events, restart the producer |
BufferExhaustedException / blocked send() | Producing faster than the broker accepts | Increase buffer.memory, batching, add partitions or brokers, apply backpressure |
Problem 3: Consumers Not Making Progress
| Symptom | Check | Fix |
|---|---|---|
| Lag grows on all partitions | Processing time per record, downstream slowness | Scale consumers (up to partitions), batch downstream writes, fix the slow dependency |
| Lag grows on one partition | Hot key or stuck record | Check partition sizes, look at the consumer log for repeated errors on one offset |
Group in PreparingRebalance or frequent rebalances | Logs show poll interval or session timeout events | Lower max.poll.records, raise max.poll.interval.ms, use cooperative or static membership |
| Consumer reads nothing | auto.offset.reset=latest, wrong group, ACL on group missing | Check group state and ACLs, reset offsets deliberately |
| Stuck forever on the same offset | Poison message and an error loop | Skip with a dead-letter handler, or reset the offset past it after investigation |
OffsetOutOfRangeException | Committed offset was deleted by retention (consumer was down too long) | Reset to earliest or latest based on business rules, consider longer retention or alerts on lag |
Problem 4: Disk Full
- Stop the growth: pause the biggest producers or add quota, reduce
retention.mson the largest non-critical topics (dynamic config) - Check which topics use space:
kafka-log-dirs.sh --describe - Look for compacted topics that cannot compact (dirty ratio), huge
__consumer_offsetsor transaction topics, and old segments kept by the active segment rule - Add disk or move partitions to other brokers (throttled reassignment)
- Prevent: alerts at 70 and 85 percent, retention limits per topic, capacity reviews
Never delete segment files by hand while the broker runs: Deleting files in a partition folder can corrupt the log. Use retention settings or the supported tools instead. A full disk can crash the broker, and recovery after an unclean shutdown can take a long time.
Problem 5: Under-Replicated or Offline Partitions
| Cause | Evidence | Fix |
|---|---|---|
| A broker is down | Broker process missing, logs show shutdown or crash | Restart, investigate crash reason (OOM, disk, power) |
| Follower too slow | IsrShrinks, high disk or network usage on that broker | Fix I/O or network, raise num.replica.fetchers, throttle reassignment traffic |
| Long GC pauses | GC log shows multi-second pauses, ZK/controller session timeouts | Tune heap and GC, reduce partitions per broker |
| Overloaded cluster | Request handler idle percentage low | Add brokers, spread partitions, reduce load |
| All ISR members gone | Partition has no leader | Bring back an ISR replica. Unclean election only as a last, data-loss-accepting decision |
Problem 6: Broker Does Not Start
| Log message | Meaning |
|---|---|
No readable meta.properties files found | Storage not formatted, or wrong log.dirs |
Cluster ID mismatch | Directory belongs to a different cluster |
java.io.IOException: Too many open files | Raise nofile limits |
java.lang.OutOfMemoryError: Map failed | Raise vm.max_map_count |
Corrupt index found and recovery taking long | Unclean shutdown, broker is rebuilding indexes. Wait, and plan graceful shutdowns |
Failed to ... the controller quorum | Controller listener, voters list or firewall wrong |
Problem 7: Duplicates, Missing or Out-of-Order Data
- Duplicates: at-least-once delivery. Make consumers idempotent, enable producer idempotence
- Missing data: check
acks, unclean elections, retention (data deleted before read), consumer committed too early, wrongauto.offset.reset - Out of order: different keys go to different partitions. Same key must be same partition. Check retries with
max.in.flightabove 1 without idempotence, and producers using multiple threads with different keys
Incident Runbook Template
| Step | Question |
|---|---|
| Detect | Which alert fired? Who is affected? Since when? |
| Assess | Cluster, topic, group or client? Data at risk? |
| Mitigate | Smallest safe action that stops customer impact |
| Fix | Root cause change, tested in staging when possible |
| Verify | Metrics back to normal, lag drained, no data gaps |
| Learn | Blameless review: timeline, cause, what monitoring or automation would catch it earlier |
Conclusion
Troubleshoot Kafka with a method: look at cluster health first, then the client, then the infrastructure. Most issues are wrong advertised listeners, under-replicated partitions, slow consumers, rebalances, full disks or security misconfiguration.
Quick Summary: advertised.listeners; ISR/URP; poll interval + rebalance; disk alerts; method: what changed, scope, mitigate.

