Kafka QuickStart, advertised.host.name gives kafka.common.LeaderNotAvailableException
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a powerful distributed streaming platform that enables you to process and handle streams of data effectively. It is used extensively for building real-time streaming data pipelines and applications. When setting up Kafka, one common issue that developers might encounter is kafka.common.LeaderNotAvailableException. Here, we explore how this issue can come up, particularly in connection with advertised.host.name configuration, and provide practical ways to resolve it.
Understanding Kafka LeaderNotAvailableException
This exception typically occurs when a Kafka client requests metadata for one or more topics and the leader of those topics is not available. The "leader" here refers to the broker responsible for managing reads and writes for a partition of a topic. Here are common reasons behind this exception:
- New Topic Creation: Right after creating a new topic, it may take some time for all brokers to get synchronized and for a leader to be elected for the partition.
- Broker Issues: If the broker set as the leader for a partition is down or unable to communicate with other brokers or clients.
- Configuration Missettings: Misconfiguration in server settings or client settings can also lead to this error.
Role of advertised.host.name
In Kafka, the advertised.host.name configuration plays a crucial role in network communication. It tells other brokers and clients how to reach this particular broker. If this setting is incorrectly configured, clients may not be able to connect to the broker, and as a result, you could see LeaderNotAvailableException.
Example Scenario
Consider a Kafka setup where you have three brokers with the following settings:
If advertised.host.name is set to an unreachable IP or incorrect hostname, any client trying to connect to these brokers will fail, potentially leading to LeaderNotAvailableException.
How to Fix the Issue
To resolve the LeaderNotAvailableException regarding the advertised.host.name, follow these steps:
- Review Broker Configurations: Ensure that
advertised.host.name(oradvertised.listenersin newer versions) is correctly set to an IP address or hostname that is reachable by all other brokers and clients. - Check Broker Logs: Review the logs of your Kafka brokers to look for any warnings or errors that could indicate why a leader is not being correctly elected or announced.
- Restart Brokers: Sometimes simply restarting the Kafka brokers can help, as it triggers a new leader election process.
- Kafka Version Compatibility: Make sure that the Kafka client’s version is compatible with the broker’s version, as mismatches can sometimes lead to unexpected errors.
Summary Table
| Issue Component | Typical Cause | Resolution Strategy |
| Leader Election | New topics or broker failures | Wait for automatic resolution or force re-election |
| Configuration | Incorrect advertised.host.name | Set correct IP or hostname reachable by all clients and brokers |
| Network Issues | Broker not reachable | Verify network settings and firewall rules |
Additional Notes
- Using
advertised.listeners: For newer versions of Kafka, it's recommended to useadvertised.listenersinstead ofadvertised.host.nameas it provides more flexibility and clarity. - Client Configuration: Ensure that clients also have the correct settings to connect to the Kafka cluster. This includes proper bootstrap servers and client ID configurations.
Dealing with issues like LeaderNotAvailableException requires a good understanding of Kafka architecture and often a hands-on approach to diagnosing and fixing configuration or operational problems. Monitoring tools and careful logging can also aid in early detection and resolution of such issues in a Kafka environment.
Related reading
- Kafka Quorum-based approach to elect the new leader?
- kafka readiness probes failing
- Kafka Rebalancing and listeners pitfalls
- Kafka Rebalancing. Duplicate processing issue
- Kafka Rebalancing issues when I kill one consumer
- KAFKA restart issue Unable to restart kafka without deleting /tmp/kafka-logs
- Kafka RecordMetadata use?
- Kafka Reduce Lag for Consumer

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.