Kafka Troubleshooting
Diagnostic procedures and solutions for common Apache Kafka issues.
Troubleshooting Methodology
Section titled “Troubleshooting Methodology”Information Gathering Checklist
Section titled “Information Gathering Checklist”| Category | Information to Collect |
|---|---|
| Errors | Exception messages, error codes |
| Metrics | Relevant JMX metrics, lag, throughput |
| Logs | Broker logs, client logs |
| Configuration | Broker, producer, consumer configs |
| Recent changes | Deployments, config changes, scaling |
| Scope | All topics/partitions or specific ones |
| Timeline | When did issue start, pattern |
Common Issues
Section titled “Common Issues”Under-Replicated Partitions
Section titled “Under-Replicated Partitions”Symptoms:
UnderReplicatedPartitionsmetric > 0kafka-topics.sh --describe --under-replicated-partitionsshows partitions
Causes:
| Cause | Investigation |
|---|---|
| Broker down | Check broker status, logs |
| Slow broker | Check disk I/O, CPU, network |
| Network issues | Check connectivity between brokers |
| Large messages | Check replica.fetch.max.bytes |
| High load | Check throughput, add capacity |
Resolution:
# Check which partitions are under-replicatedkafka-topics.sh --bootstrap-server kafka:9092 \ --describe --under-replicated-partitions
# Check broker statuskafka-broker-api-versions.sh --bootstrap-server kafka1:9092
# Check replica lagkafka-replica-verification.sh --broker-list kafka1:9092,kafka2:9092 \ --topic-white-list ".*"Offline Partitions
Section titled “Offline Partitions”Symptoms:
OfflinePartitionsCountmetric > 0- Producers fail with
NotLeaderForPartitionException
Causes:
| Cause | Resolution |
|---|---|
| All replicas down | Restart brokers with replicas |
| Unclean leader election disabled | Enable unclean.leader.election.enable (data loss risk) or recover broker |
| Disk failure | Replace disk, restore from replica |
Resolution:
# Find offline partitionskafka-topics.sh --bootstrap-server kafka:9092 \ --describe --unavailable-partitions
# Check replica statuskafka-topics.sh --bootstrap-server kafka:9092 \ --describe --topic <topic>
# Force leader election (if unclean election is acceptable)kafka-leader-election.sh --bootstrap-server kafka:9092 \ --election-type UNCLEAN \ --topic <topic> --partition <partition>Consumer Lag
Section titled “Consumer Lag”Symptoms:
- Consumer lag growing
- Processing falling behind
Diagnosis:
# Check consumer lagkafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --describe --group <group>
# Output shows:# TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAGCauses and Resolutions:
| Cause | Resolution |
|---|---|
| Slow processing | Optimize processing logic, add consumers |
| Too few consumers | Add consumers (up to partition count) |
| Rebalancing | Use cooperative rebalancing, static membership |
| Large messages | Increase fetch size, processing capacity |
| External dependency slow | Optimize external calls, add buffering |
Producer Timeouts
Section titled “Producer Timeouts”Symptoms:
TimeoutExceptionin producerdelivery.timeout.msexceeded
Causes:
| Cause | Investigation |
|---|---|
| Broker unavailable | Check broker health, connectivity |
| No leader | Check partition leadership |
| ISR too small | Check ISR, min.insync.replicas |
| Network issues | Check network latency, packet loss |
| Overloaded broker | Check broker metrics, request queue |
Resolution:
# Check broker availabilitykafka-broker-api-versions.sh --bootstrap-server kafka:9092
# Check partition leaderskafka-topics.sh --bootstrap-server kafka:9092 \ --describe --topic <topic>
# Check request metrics (JMX)# kafka.network:type=RequestMetrics,name=TotalTimeMs,request=ProduceNotEnoughReplicasException
Section titled “NotEnoughReplicasException”Symptoms:
- Producer fails with
NotEnoughReplicasException min.insync.replicasnot satisfied
Cause: ISR size < min.insync.replicas
Resolution:
# Check ISR for topickafka-topics.sh --bootstrap-server kafka:9092 \ --describe --topic <topic>
# Check under-replicated partitionskafka-topics.sh --bootstrap-server kafka:9092 \ --describe --under-replicated-partitions
# Resolution options:# 1. Fix unhealthy brokers to restore ISR# 2. Temporarily reduce min.insync.replicas (reduces durability)kafka-configs.sh --bootstrap-server kafka:9092 \ --entity-type topics --entity-name <topic> \ --alter --add-config min.insync.replicas=1Consumer Rebalancing Storm
Section titled “Consumer Rebalancing Storm”Symptoms:
- Frequent rebalances
- Consumer frequently in
REBALANCINGstate - High latency, processing gaps
Causes:
| Cause | Resolution |
|---|---|
| Processing too slow | Increase max.poll.interval.ms, optimize processing |
| GC pauses | Tune JVM GC |
| Heartbeat issues | Ensure heartbeat.interval.ms < session.timeout.ms / 3 |
| Consumer crashes | Fix consumer stability |
| Network instability | Fix network issues |
Resolution:
# Consumer configurationmax.poll.interval.ms=600000 # Increase if processing is slowsession.timeout.ms=45000 # Defaultheartbeat.interval.ms=3000 # Should be < session.timeout.ms / 3
# Use cooperative rebalancingpartition.assignment.strategy=org.apache.kafka.clients.consumer.CooperativeStickyAssignor
# Use static membershipgroup.instance.id=consumer-host-1Log Analysis
Section titled “Log Analysis”Important Log Patterns
Section titled “Important Log Patterns”| Pattern | Meaning |
|---|---|
ERROR | Error requiring attention |
WARN | Warning, potential issue |
Marking partition.*offline | Partition lost leadership |
ISR.*shrunk | Replica fell out of sync |
ISR.*expanded | Replica rejoined ISR |
NotLeaderForPartition | Leader changed during request |
ReplicaFetcherThread.*shutdown | Replication stopped |
Connection to node.*could not be established | Network connectivity issue |
Log Locations
Section titled “Log Locations”| Component | Default Location |
|---|---|
| Broker | /var/log/kafka/server.log or $KAFKA_HOME/logs/server.log |
| Controller | /var/log/kafka/controller.log |
| State change | /var/log/kafka/state-change.log |
| Request log | /var/log/kafka/kafka-request.log (if enabled) |
Enabling Debug Logging
Section titled “Enabling Debug Logging”# Increase log level dynamicallykafka-configs.sh --bootstrap-server kafka:9092 \ --entity-type broker-loggers \ --entity-name 1 \ --alter \ --add-config kafka.server=DEBUG
# Reset to defaultkafka-configs.sh --bootstrap-server kafka:9092 \ --entity-type broker-loggers \ --entity-name 1 \ --alter \ --delete-config kafka.serverDiagnostic Commands
Section titled “Diagnostic Commands”Cluster Health
Section titled “Cluster Health”# List brokerskafka-broker-api-versions.sh --bootstrap-server kafka:9092
# Check cluster metadata (KRaft)kafka-metadata.sh --snapshot /var/kafka/data/__cluster_metadata-0/00000000000000000000.log \ --command "describe"
# Check under-replicated partitionskafka-topics.sh --bootstrap-server kafka:9092 \ --describe --under-replicated-partitions
# Check offline partitionskafka-topics.sh --bootstrap-server kafka:9092 \ --describe --unavailable-partitionsTopic Health
Section titled “Topic Health”# Describe topickafka-topics.sh --bootstrap-server kafka:9092 \ --describe --topic <topic>
# Check topic configurationkafka-configs.sh --bootstrap-server kafka:9092 \ --entity-type topics --entity-name <topic> --describe
# Verify replica assignmentkafka-topics.sh --bootstrap-server kafka:9092 \ --describe --topic <topic>Consumer Health
Section titled “Consumer Health”# List consumer groupskafka-consumer-groups.sh --bootstrap-server kafka:9092 --list
# Describe consumer groupkafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --describe --group <group>
# Check group statekafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --describe --group <group> --state
# Check memberskafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --describe --group <group> --members --verboseLog Inspection
Section titled “Log Inspection”# Dump log segmentkafka-dump-log.sh --files /var/kafka-logs/<topic>-<partition>/00000000000000000000.log \ --print-data-log
# Check log segment metadatakafka-dump-log.sh --files /var/kafka-logs/<topic>-<partition>/00000000000000000000.log \ --deep-iteration
# Verify log integritykafka-log-dirs.sh --bootstrap-server kafka:9092 \ --describe --topic-list <topic>Error Reference
Section titled “Error Reference”Producer Errors
Section titled “Producer Errors”| Exception | Cause | Resolution |
|---|---|---|
TimeoutException | Delivery timeout exceeded | Check broker health, network, increase timeout |
NotLeaderForPartitionException | Leader changed | Retry (usually automatic) |
NotEnoughReplicasException | ISR < min.insync.replicas | Fix broker health |
RecordTooLargeException | Message exceeds max size | Increase max.request.size or reduce message size |
SerializationException | Serialization failed | Fix serializer configuration |
AuthorizationException | ACL denied access | Grant required ACLs |
SaslAuthenticationException | Authentication failed | Check credentials |
Consumer Errors
Section titled “Consumer Errors”| Exception | Cause | Resolution |
|---|---|---|
CommitFailedException | Rebalance during commit | Handle in rebalance listener |
WakeupException | wakeup() called | Normal for graceful shutdown |
OffsetOutOfRangeException | Offset no longer available | Reset offset or handle with auto.offset.reset |
DeserializationException | Deserialization failed | Fix deserializer, handle poison pills |
GroupAuthorizationException | No access to consumer group | Grant group ACL |
TopicAuthorizationException | No access to topic | Grant topic ACL |
Broker Errors
Section titled “Broker Errors”| Error | Cause | Resolution |
|---|---|---|
OutOfMemoryError | Heap exhausted | Increase heap, check for leaks |
IOException: No space left | Disk full | Add storage, adjust retention |
Too many open files | File descriptor limit | Increase ulimit |
Connection refused | Broker down or listener misconfigured | Check broker status, listener config |
Performance Issues
Section titled “Performance Issues”High Latency
Section titled “High Latency”Investigation:
# Check request latency (JMX)# kafka.network:type=RequestMetrics,name=TotalTimeMs,request=Produce# kafka.network:type=RequestMetrics,name=TotalTimeMs,request=FetchConsumer
# Check request queue# kafka.network:type=RequestChannel,name=RequestQueueSizeCommon causes:
| Cause | Resolution |
|---|---|
| Slow disk | Use SSDs, check I/O wait |
| High CPU | Add capacity, optimize |
| Network congestion | Check bandwidth, optimize |
| GC pauses | Tune JVM GC settings |
| Large batches | Reduce batch size |
Low Throughput
Section titled “Low Throughput”Investigation:
- Check producer batching (
batch.size,linger.ms) - Check compression settings
- Check consumer fetch settings
- Check broker I/O capacity
Common causes:
| Cause | Resolution |
|---|---|
| Small batches | Increase batch.size, linger.ms |
| No compression | Enable compression |
| Small fetch | Increase fetch.min.bytes |
| Disk I/O bottleneck | Add disks, use faster storage |
| Network bottleneck | Add bandwidth |
Getting Help
Section titled “Getting Help”Information to Include
Section titled “Information to Include”When seeking help, include:
- Kafka version
- Error messages (full stack trace)
- Relevant configuration
- Metrics (throughput, latency, lag)
- Cluster size (brokers, partitions)
- Recent changes
- Steps to reproduce
Resources
Section titled “Resources”Related Documentation
Section titled “Related Documentation”- Common Errors - Error reference
- Log Analysis - Log interpretation guide
- Diagnosis - Diagnostic procedures
- Operations - Operational procedures
- Monitoring - Metrics and alerting