# Common Apache Kafka Issues and Resolutions
This document outlines 30 common issues encountered when operating Apache Kafka and provides recommended solutions for each. It's intended to assist operations teams in troubleshooting and maintaining a healthy Kafka ecosystem.
## 1. **Broker Not Starting**
**Issue:** Kafka broker fails to start, possibly due to misconfiguration or port conflicts.
**Resolution:**
- **Check Logs:** Review `server.log` for specific error messages.
- **Validate Configuration:** Ensure `server.properties` has correct settings.
- **Port Availability:** Confirm that the configured ports (default 9092) are not in use.
- **Java Version:** Ensure compatibility with the installed Java version.
## 2. **Zookeeper Connection Issues**
**Issue:** Brokers cannot connect to Zookeeper, leading to cluster instability.
**Resolution:**
- **Zookeeper Status:** Verify that Zookeeper ensemble is running.
- **Configuration Check:** Ensure `zookeeper.connect` in `server.properties` is correct.
- **Network Connectivity:** Check network connectivity and firewall settings between brokers and Zookeeper.
- **Logs Inspection:** Examine Zookeeper and broker logs for connection errors.
## 3. **Under-Replicated Partitions**
**Issue:** Some partitions are under-replicated, risking data loss.
**Resolution:**
- **Broker Health:** Check if any brokers are down and restart them if necessary.
- **Replication Factor:** Ensure the replication factor is appropriate for the cluster size.
- **Disk Space:** Verify that brokers have sufficient disk space.
- **Network Issues:** Resolve any network partitioning problems.
## 4. **High Latency in Message Delivery**
**Issue:** Increased time in delivering messages from producers to consumers.
**Resolution:**
- **Broker Performance:** Monitor CPU, memory, and I/O usage on brokers.
- **Network Bandwidth:** Ensure sufficient network capacity and low latency.
- **Configuration Tuning:** Adjust `linger.ms`, `batch.size`, and `acks` settings for producers.
- **Consumer Throughput:** Check if consumers are keeping up with the incoming message rate.
## 5. **Consumer Lag**
**Issue:** Consumers are falling behind the latest messages, leading to lag.
**Resolution:**
- **Consumer Throughput:** Optimize consumer processing logic to handle higher message rates.
- **Increase Consumers:** Add more consumer instances to the consumer group.
- **Partition Rebalancing:** Ensure partitions are evenly distributed among consumers.
- **Commit Strategy:** Use appropriate commit intervals to avoid unnecessary reprocessing.
## 6. **Topic Not Found Errors**
**Issue:** Producers or consumers cannot find the specified topic.
**Resolution:**
- **Topic Creation:** Ensure the topic exists; create it if necessary using `kafka-topics.sh`.
- **Permissions:** Verify that the user has the necessary permissions to access the topic.
- **Configuration Check:** Confirm that `auto.create.topics.enable` is set correctly based on your needs.
- **Namespace Issues:** Ensure correct casing and spelling of the topic name.
## 7. **Disk Usage Exceeds Limits**
**Issue:** Brokers run out of disk space, causing failures.
**Resolution:**
- **Log Retention Policies:** Configure appropriate `log.retention.hours` or `log.retention.bytes` to limit disk usage.
- **Increase Disks:** Add more disk space to brokers as needed.
- **Delete Unnecessary Data:** Manually delete unused topics or logs if urgent.
- **Monitor Usage:** Implement monitoring to alert before disk usage becomes critical.
## 8. **Leader Election Failures**
**Issue:** Partition leaders fail to be elected, leading to unavailability.
**Resolution:**
- **Broker Availability:** Ensure that a majority of brokers are up and can communicate.
- **Zookeeper Health:** Verify that Zookeeper is functioning correctly.
- **Configuration Check:** Ensure correct `min.insync.replicas` settings.
- **Network Stability:** Resolve any network issues causing communication failures.
## 9. **Authentication Failures**
**Issue:** Producers or consumers cannot authenticate with the Kafka cluster.
**Resolution:**
- **Credentials Verification:** Check that correct SASL or SSL credentials are being used.
- **Configuration Settings:** Ensure `ssl.keystore.location`, `ssl.truststore.location`, and related configurations are correct.
- **Certificate Validity:** Verify that SSL certificates are valid and not expired.
- **Permission Settings:** Confirm that ACLs permit access for the authenticated user.
## 10. **Authorization Errors**
**Issue:** Authenticated users are denied access to perform certain actions.
**Resolution:**
- **ACL Configuration:** Review and update Access Control Lists to grant necessary permissions.
- **User Roles:** Ensure users have appropriate roles assigned.
- **Topic Permissions:** Verify that users have access rights to specific topics.
- **Broker Configuration:** Check `authorizer.class.name` is correctly set in `server.properties`.
## 11. **Slow Fetch Requests**
**Issue:** Consumers experience delays when fetching messages from brokers.
**Resolution:**
- **Broker Load:** Assess and balance the load across brokers.
- **Fetch Configuration:** Tune `fetch.min.bytes` and `fetch.max.wait.ms` settings for consumers.
- **Network Performance:** Ensure low latency and high bandwidth connections.
- **Disk I/O:** Optimize disk performance on brokers to handle fetch requests efficiently.
## 12. **Producer Timeouts**
**Issue:** Producers encounter timeouts when sending messages.
**Resolution:**
- **Producer Retries:** Increase the number of retries and adjust `retry.backoff.ms`.
- **Timeout Settings:** Modify `request.timeout.ms` to accommodate longer operations.
- **Broker Availability:** Ensure brokers are available and responsive.
- **Optimize Batch Settings:** Adjust `batch.size` and `linger.ms` for better performance.
## 13. **Frequent GC Pauses**
**Issue:** Frequent Garbage Collection pauses impact broker performance.
**Resolution:**
- **JVM Tuning:** Optimize JVM heap size and garbage collector settings.
- **Kafka Version:** Upgrade to a Kafka version with improved GC performance.
- **Resource Allocation:** Allocate sufficient memory to brokers without over-provisioning.
- **Monitor GC Logs:** Analyze GC logs to identify and address memory issues.
## 14. **High CPU Usage on Brokers**
**Issue:** Brokers experience high CPU usage, potentially degrading performance.
**Resolution:**
- **Process Monitoring:** Identify processes consuming excessive CPU.
- **Optimize Configurations:** Adjust Kafka configurations to reduce CPU load, such as compression settings.
- **Hardware Upgrade:** Scale up broker hardware if necessary.
- **Load Balancing:** Distribute load evenly across the cluster by adding more brokers or redistributing partitions.
## 15. **Message Duplication**
**Issue:** Consumers receive duplicate messages, leading to processing inconsistencies.
**Resolution:**
- **Producer Idempotence:** Enable idempotent producers by setting `enable.idempotence=true`.
- **Idempotent Configurations:** Ensure proper configuration of `transactional.id` for transactional producers.
- **Consumer Logic:** Implement idempotent processing on the consumer side to handle duplicates gracefully.
- **Offset Management:** Ensure accurate offset commits to prevent reprocessing after failures.
## 16. **Message Loss**
**Issue:** Messages are lost during production or consumption.
**Resolution:**
- **Replication Factor:** Set an appropriate replication factor to prevent data loss.
- **Acknowledgments (`acks`):** Configure producers with `acks=all` to ensure all replicas acknowledge receipt.
- **Monitor Replication:** Regularly check replication status and resolve under-replicated partitions.
- **Durable Storage:** Ensure brokers have reliable storage systems to prevent data loss.
## 17. **Inconsistent Topic Configurations**
**Issue:** Topics have inconsistent configurations leading to unexpected behavior.
**Resolution:**
- **Standardize Configurations:** Define and adhere to standard topic configurations across the cluster.
- **Automated Tools:** Use configuration management tools to enforce consistent settings.
- **Regular Audits:** Periodically review topic configurations to identify and rectify discrepancies.
- **Documentation:** Maintain thorough documentation of topic configurations and policies.
## 18. **Schema Registry Issues**
**Issue:** Problems with the Schema Registry affect message serialization/deserialization.
**Resolution:**
- **Schema Compatibility:** Ensure schemas are compatible with existing ones to prevent serialization errors.
- **Registry Availability:** Monitor and maintain high availability of the Schema Registry service.
- **Client Configurations:** Verify that producers and consumers are correctly configured to use the Schema Registry.
- **Version Management:** Manage and document schema versions to avoid conflicts.
## 19. **Delayed Topic Creation**
**Issue:** Automatic topic creation is slow or fails, delaying operations.
**Resolution:**
- **Pre-create Topics:** Use `kafka-topics.sh` to create topics proactively instead of relying on auto-creation.
- **Configuration Adjustment:** If using auto-creation, ensure `auto.create.topics.enable=true` and check related settings.
- **Resource Allocation:** Ensure sufficient broker resources to handle topic creation requests promptly.
- **Monitor Requests:** Track topic creation requests and resolve any errors from logs.
## 20. **Inadequate Monitoring and Alerting**
**Issue:** Lack of proper monitoring leads to unnoticed issues and delayed responses.
**Resolution:**
- **Implement Monitoring Tools:** Use tools like Prometheus, Grafana, and Kafka's JMX metrics to monitor cluster health.
- **Set Up Alerts:** Configure alerts for critical metrics such as broker down, high lag, disk usage, and replication issues.
- **Regular Audits:** Conduct periodic reviews of monitoring dashboards and alert configurations.
- **Logging Practices:** Ensure comprehensive logging is in place for all Kafka components.
## 21. **Network Partitions**
**Issue:** Network issues cause partitions in the Kafka cluster, leading to inconsistent states.
**Resolution:**
- **Network Stability:** Ensure a stable and reliable network infrastructure.
- **Redundancy:** Implement network redundancy to prevent single points of failure.
- **Monitor Connectivity:** Use monitoring tools to detect and alert on network partitions.
- **Zookeeper Configuration:** Optimize Zookeeper settings for network resilience.
## 22. **Incorrect Partition Distribution**
**Issue:** Partitions are unevenly distributed across brokers, causing load imbalance.
**Resolution:**
- **Rebalance Partitions:** Use Kafka's partition reassignment tool to distribute partitions evenly.
- **Automated Tools:** Implement automated partition management tools to maintain balance as the cluster scales.
- **Monitor Broker Load:** Continuously monitor broker loads and adjust partition distribution as needed.
- **Topic Configuration:** Set appropriate number of partitions during topic creation to facilitate balanced distribution.
## 23. **Stuck Offsets**
**Issue:** Consumers unable to commit offsets, leading to processing issues.
**Resolution:**
- **Check Permissions:** Ensure consumers have permissions to commit offsets.
- **Kafka Configuration:** Verify `group.id` and related consumer configurations are correct.
- **Broker Availability:** Ensure that the consumer coordinator is reachable and functioning.
- **Offset Management:** Use Kafka’s `kafka-consumer-groups.sh` to inspect and manage offsets.
## 24. **Misconfigured Retention Policies**
**Issue:** Log retention settings lead to unexpected data deletion or excessive storage use.
**Resolution:**
- **Set Appropriate Retention:** Configure `log.retention.hours` and `log.retention.bytes` based on storage capacity and data retention needs.
- **Topic-Specific Settings:** Override default retention settings for specific topics as required.
- **Monitor Retention:** Regularly review retention policies and adjust based on usage patterns.
- **Automate Management:** Use scripts or tools to manage retention policies dynamically as the cluster evolves.
## 25. **Underperforming Consumers**
**Issue:** Consumers cannot keep up with the message rate, leading to lag.
**Resolution:**
- **Optimize Consumer Code:** Improve processing efficiency in consumer applications.
- **Increase Consumer Instances:** Scale out the consumer group by adding more consumer instances.
- **Partition Distribution:** Ensure partitions are evenly distributed among consumers to maximize parallelism.
- **Batch Processing:** Use batch processing to handle multiple messages in a single operation.
## 26. **High Memory Usage on Brokers**
**Issue:** Brokers consume excessive memory, potentially leading to crashes or performance issues.
**Resolution:**
- **Heap Allocation:** Adjust JVM heap sizes to match broker resource requirements.
- **Memory Leaks:** Identify and fix any memory leaks in broker processes.
- **Monitor Usage:** Continuously monitor memory usage and set alerts for abnormal consumption.
- **Optimize Configurations:** Tune Kafka configurations such as `num.io.threads` and `num.network.threads` to manage memory usage effectively.
## 27. **Inadequate Backup and Recovery**
**Issue:** Lack of proper backup strategies leads to data loss in case of failures.
**Resolution:**
- **Regular Backups:** Implement regular backups of Kafka logs and configurations.
- **Disaster Recovery Plan:** Develop and test a comprehensive disaster recovery plan.
- **Replication Strategies:** Use appropriate replication factors to ensure data redundancy.
- **Third-Party Tools:** Utilize backup tools designed for Kafka clusters to streamline the process.
## 28. **Inconsistent Cluster Configurations**
**Issue:** Brokers have inconsistent configurations, causing unpredictable behavior.
**Resolution:**
- **Configuration Management:** Use centralized configuration management tools like Ansible, Puppet, or Chef.
- **Templates and Versioning:** Maintain configuration templates and version control to track changes.
- **Automate Deployments:** Automate broker configuration deployments to ensure consistency.
- **Regular Audits:** Periodically verify that all brokers adhere to the standardized configurations.
## 29. **Unbalanced Leader Distribution**
**Issue:** Leaders are unevenly distributed across brokers, causing hotspots.
**Resolution:**
- **Reassign Leaders:** Use Kafka's preferred leader election tool or manual reassignment to balance leaders.
- **Automated Leader Balancing:** Implement tools that automatically monitor and rebalance leader distribution.
- **Monitor Broker Load:** Keep track of leader distribution and adjust as brokers are added or removed.
- **Optimize Partitioning:** Ensure partitioning strategy promotes even leader distribution from the outset.
## 30. **Unsupported Kafka Versions**
**Issue:** Running outdated Kafka versions lacking important features and security patches.
**Resolution:**
- **Regular Upgrades:** Schedule and perform regular Kafka version upgrades following best practices.
- **Compatibility Checks:** Ensure compatibility of client applications and dependencies before upgrading.
- **Test Environments:** Validate upgrades in staging environments to identify potential issues.
- **Review Release Notes:** Stay informed about new features, improvements, and critical fixes in each release.
---
**Note:** Regular monitoring, proactive maintenance, and adherence to best practices are essential to prevent and quickly resolve these common Kafka issues. Always refer to the [official Apache Kafka documentation](https://kafka.apache.org/documentation/) for detailed guidance and updates.