This runbook covers troubleshooting procedures for Apache Kafka message queue issues in the Poultry Platform.
Kafka Version: Confluent Platform 7.5 Deployment: Kubernetes / Docker Compose Client: Spring Kafka
- Quick Diagnostics
- Broker Issues
- Producer Issues
- Consumer Issues
- Topic Issues
- Zookeeper Issues
- Performance Issues
- Recovery Procedures
# Kubernetes: Check Kafka pods
kubectl get pods -n poultry-platform -l app=kafka
# Check Kafka logs
kubectl logs -f kafka-0 -n poultry-platform --tail=100
# Check Zookeeper pods
kubectl get pods -n poultry-platform -l app=zookeeper
# Application health
curl -s https://api.poultry-platform.com/api/actuator/health | jq '.components.kafka'# Connect to Kafka pod
kubectl exec -it kafka-0 -n poultry-platform -- bash
# List topics
kafka-topics --bootstrap-server localhost:9092 --list
# Describe cluster
kafka-metadata --bootstrap-server localhost:9092 --describe --status
# Check broker IDs
kafka-broker-api-versions --bootstrap-server localhost:9092
# Check consumer groups
kafka-consumer-groups --bootstrap-server localhost:9092 --listSymptoms:
- Kafka pod in CrashLoopBackOff
- "Broker not available" errors in application
Diagnosis:
# Check pod events
kubectl describe pod kafka-0 -n poultry-platform
# Check logs for startup errors
kubectl logs kafka-0 -n poultry-platform --previous
# Check Zookeeper connectivity
kubectl exec -it kafka-0 -n poultry-platform -- \
zookeeper-shell zookeeper:2181 ls /brokers/idsResolution:
-
Zookeeper connectivity issues:
# Verify Zookeeper is running kubectl get pods -n poultry-platform -l app=zookeeper # Test connectivity kubectl exec -it kafka-0 -n poultry-platform -- \ nc -zv zookeeper 2181
-
Clean restart:
kubectl delete pod kafka-0 -n poultry-platform
-
Check disk space:
kubectl exec -it kafka-0 -n poultry-platform -- df -h /var/lib/kafka
Symptoms:
- ISR (In-Sync Replicas) shrinking
- Partition leadership changes
Diagnosis:
# Check under-replicated partitions
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-topics --bootstrap-server localhost:9092 \
--describe --under-replicated-partitions
# Check ISR
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-topics --bootstrap-server localhost:9092 \
--describe --topic <topic-name>Resolution:
- Check network between brokers
- Check broker disk I/O
- Increase
replica.lag.time.max.msif legitimate lag - Restart lagging broker
Symptoms:
- "No space left on device" errors
- New messages not being accepted
Diagnosis:
# Check disk usage
kubectl exec -it kafka-0 -n poultry-platform -- df -h /var/lib/kafka
# Check log segment sizes
kubectl exec -it kafka-0 -n poultry-platform -- \
du -sh /var/lib/kafka/data/*Resolution:
-
Emergency cleanup:
# Reduce retention temporarily kafka-configs --bootstrap-server localhost:9092 \ --alter --entity-type topics --entity-name <topic> \ --add-config retention.ms=3600000 # 1 hour # Force log cleanup kafka-configs --bootstrap-server localhost:9092 \ --alter --entity-type topics --entity-name <topic> \ --add-config cleanup.policy=delete
-
Expand volume (if using dynamic provisioning)
-
Delete old topics if no longer needed
Symptoms:
- Messages not appearing in topics
- Producer timeout errors
Diagnosis:
# Check application logs for producer errors
kubectl logs deployment/poultry-backend -n poultry-platform | grep -i "producer\|kafka" | tail -30
# Test producer from command line
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-console-producer --bootstrap-server localhost:9092 --topic test-topic
# Check topic exists
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-topics --bootstrap-server localhost:9092 --describe --topic <topic-name>Resolution:
-
Verify topic exists and create if needed:
kafka-topics --bootstrap-server localhost:9092 \ --create --topic <topic-name> \ --partitions 3 --replication-factor 1
-
Check producer configuration:
spring: kafka: producer: bootstrap-servers: kafka:9092 key-serializer: org.apache.kafka.common.serialization.StringSerializer value-serializer: org.springframework.kafka.support.serializer.JsonSerializer acks: all retries: 3
-
Check for serialization errors in logs
Symptoms:
- "TimeoutException" in producer
- Messages taking too long to acknowledge
Diagnosis:
# Check broker latency
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-producer-perf-test --topic test-topic \
--throughput 100 --num-records 1000 \
--record-size 100 --producer-props bootstrap.servers=localhost:9092
# Check for slow leader election
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-topics --bootstrap-server localhost:9092 --describe --topic <topic>Resolution:
-
Increase producer timeout:
spring: kafka: producer: properties: request.timeout.ms: 30000 delivery.timeout.ms: 120000
-
Reduce batch size for faster sends:
spring: kafka: producer: batch-size: 16384 linger-ms: 5
-
Check network connectivity to brokers
Symptoms:
- Messages not being processed
- Consumer lag increasing
- Delayed order processing
Diagnosis:
# Check consumer lag
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-consumer-groups --bootstrap-server localhost:9092 \
--describe --group poultry-platform
# Check specific topic lag
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-consumer-groups --bootstrap-server localhost:9092 \
--describe --group poultry-platform | grep <topic-name>
# Check consumer state
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-consumer-groups --bootstrap-server localhost:9092 \
--describe --group poultry-platform --stateResolution:
-
Scale consumers:
# Increase consumer instances (up to partition count) kubectl scale deployment poultry-backend -n poultry-platform --replicas=5 -
Check for processing errors:
kubectl logs deployment/poultry-backend -n poultry-platform | \ grep -i "consumer\|exception" | tail -50
-
Increase consumer throughput:
spring: kafka: consumer: properties: max.poll.records: 500 fetch.min.bytes: 1 fetch.max.wait.ms: 500
-
Reset offset if necessary (data loss warning):
kafka-consumer-groups --bootstrap-server localhost:9092 \ --group poultry-platform --topic <topic> \ --reset-offsets --to-latest --execute
Symptoms:
- "Rebalancing" messages in logs
- Intermittent processing delays
- Consumer group instability
Diagnosis:
# Check consumer group stability
kubectl logs deployment/poultry-backend -n poultry-platform | \
grep -i "rebalanc" | tail -20
# Check consumer heartbeats
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-consumer-groups --bootstrap-server localhost:9092 \
--describe --group poultry-platform --membersResolution:
-
Increase session timeout:
spring: kafka: consumer: properties: session.timeout.ms: 30000 heartbeat.interval.ms: 10000
-
Reduce max.poll.records if processing takes too long:
spring: kafka: consumer: properties: max.poll.records: 100 max.poll.interval.ms: 300000
-
Use static membership to reduce rebalances:
spring: kafka: consumer: properties: group.instance.id: ${HOSTNAME}
Symptoms:
- Consumer running but no messages processed
- Topic has messages but consumer shows no activity
Diagnosis:
# Check consumer group status
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-consumer-groups --bootstrap-server localhost:9092 \
--describe --group poultry-platform
# Check topic partitions and offsets
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-run-class kafka.tools.GetOffsetShell \
--broker-list localhost:9092 --topic <topic-name>
# Consume messages manually to verify
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-console-consumer --bootstrap-server localhost:9092 \
--topic <topic-name> --from-beginning --max-messages 5Resolution:
- Verify consumer group ID matches configuration
- Check auto.offset.reset setting:
spring: kafka: consumer: auto-offset-reset: earliest # or 'latest'
- Ensure topic subscription is correct
- Check for deserialization errors
Diagnosis:
# List all topics
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-topics --bootstrap-server localhost:9092 --list
# Create topic if missing
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-topics --bootstrap-server localhost:9092 \
--create --topic <topic-name> \
--partitions 6 --replication-factor 1Standard Topics in Poultry Platform:
| Topic | Partitions | Description |
|---|---|---|
| order-events | 6 | Order lifecycle events |
| payment-events | 6 | Payment status updates |
| notification-events | 3 | SMS/Push notifications |
| inventory-events | 3 | Inventory updates |
Increase partitions:
kafka-topics --bootstrap-server localhost:9092 \
--alter --topic order-events --partitions 12Note: Partitions can only be increased, not decreased.
Check and modify retention:
# Check current retention
kafka-configs --bootstrap-server localhost:9092 \
--describe --entity-type topics --entity-name <topic>
# Set retention to 7 days
kafka-configs --bootstrap-server localhost:9092 \
--alter --entity-type topics --entity-name <topic> \
--add-config retention.ms=604800000Symptoms:
- Kafka brokers not starting
- "Zookeeper connection failed" errors
Diagnosis:
# Check Zookeeper pods
kubectl get pods -n poultry-platform -l app=zookeeper
# Check Zookeeper logs
kubectl logs zookeeper-0 -n poultry-platform --tail=50
# Test Zookeeper from Kafka pod
kubectl exec -it kafka-0 -n poultry-platform -- \
zookeeper-shell zookeeper:2181 ls /Resolution:
-
Restart Zookeeper:
kubectl rollout restart statefulset/zookeeper -n poultry-platform
-
Check Zookeeper data directory:
kubectl exec -it zookeeper-0 -n poultry-platform -- \ ls -la /var/lib/zookeeper -
Verify Zookeeper service:
kubectl get svc zookeeper -n poultry-platform
Symptoms:
- "Session expired" in Kafka logs
- Broker disconnecting from cluster
Resolution:
-
Increase session timeout:
zookeeper.session.timeout.ms=30000 -
Check network stability between Kafka and Zookeeper
-
Restart affected Kafka broker
Diagnosis:
# Producer latency test
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-producer-perf-test --topic test-topic \
--throughput 1000 --num-records 10000 \
--record-size 1024 --producer-props bootstrap.servers=localhost:9092
# Consumer latency test
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-consumer-perf-test --bootstrap-server localhost:9092 \
--topic test-topic --messages 10000Resolution:
- Check broker disk I/O
- Increase
num.io.threadsandnum.network.threads - Tune producer batching:
batch.size: 32768 linger.ms: 10
Diagnosis:
# Check for unclean leader election
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-configs --bootstrap-server localhost:9092 \
--describe --entity-type brokers --entity-default
# Verify producer acks settingPrevention:
- Use
acks=allfor producers - Set
min.insync.replicas=2(with replication factor 3) - Disable unclean leader election:
unclean.leader.election.enable=false
# Stop consumers first
kubectl scale deployment poultry-backend -n poultry-platform --replicas=0
# Reset to latest offset
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-consumer-groups --bootstrap-server localhost:9092 \
--group poultry-platform --topic <topic> \
--reset-offsets --to-latest --execute
# Restart consumers
kubectl scale deployment poultry-backend -n poultry-platform --replicas=3# Reset to messages from 1 hour ago
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-consumer-groups --bootstrap-server localhost:9092 \
--group poultry-platform --topic <topic> \
--reset-offsets --to-datetime 2024-01-15T10:00:00.000 --execute# Remove broker from cluster (if corrupted)
kubectl delete pvc data-kafka-0 -n poultry-platform
# Let StatefulSet recreate
kubectl delete pod kafka-0 -n poultry-platform
# Verify broker rejoined
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-broker-api-versions --bootstrap-server localhost:9092# WARNING: This deletes all messages
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-topics --bootstrap-server localhost:9092 \
--delete --topic <topic-name>
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-topics --bootstrap-server localhost:9092 \
--create --topic <topic-name> \
--partitions 6 --replication-factor 1#!/bin/bash
# kafka-lag-check.sh
echo "=== Kafka Consumer Lag ==="
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-consumer-groups --bootstrap-server localhost:9092 \
--describe --group poultry-platform 2>/dev/null | \
awk 'NR>1 {sum+=$6} END {print "Total Lag: " sum}'#!/bin/bash
# kafka-health.sh
echo "=== Broker Status ==="
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-broker-api-versions --bootstrap-server localhost:9092 | head -5
echo -e "\n=== Under-replicated Partitions ==="
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-topics --bootstrap-server localhost:9092 \
--describe --under-replicated-partitions
echo -e "\n=== Consumer Groups ==="
kubectl exec -it kafka-0 -n poultry-platform -- \
kafka-consumer-groups --bootstrap-server localhost:9092 --listspring:
kafka:
producer:
bootstrap-servers: ${KAFKA_SERVERS:localhost:9092}
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
acks: all
retries: 3
properties:
linger.ms: 10
batch.size: 16384
buffer.memory: 33554432spring:
kafka:
consumer:
group-id: poultry-platform
auto-offset-reset: earliest
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
properties:
spring.json.trusted.packages: com.poultry.*
max.poll.records: 500
session.timeout.ms: 30000If unable to resolve:
- Check Confluent documentation
- Escalate to infrastructure team
- Consider Confluent support (if using managed service)