Quick answer
A partition currently has no elected leader, so the request can't be served yet.
- Just created the topic? Wait a second or two — this is expected and resolves on its own.
- Repeats forever, especially in Docker/Kubernetes? It's almost certainly
advertised.listeners. - Persists with a stable cluster that isn't containerized? Check whether the partition's replicas are actually all down.
Common symptoms
You may never see the exact string LEADER_NOT_AVAILABLE in your own logs and still have this exact problem — it often surfaces as one of these instead:
- Producer
send()calls never complete, or retry forever without erroring out - Consumers subscribe without error but never receive any records
- Client logs show repeated metadata refreshes that never make progress
- The initial connection succeeds, but every actual produce or fetch request hangs or times out
- A Kafka UI (Kafka UI, Conduktor, AKHQ) reports every broker as healthy while clients still can't send or receive
The exact error string
WARN [Consumer clientId=consumer-1, groupId=orders] Error while fetching metadata
with correlation id 7 : {orders=LEADER_NOT_AVAILABLE}
Every partition has exactly one leader replica; all reads and writes for that partition go through it. This message means the broker responded to a metadata request saying the orders topic's partition has no leader right now. It's a WARN, not a fatal exception, because Kafka clients automatically refresh metadata and retry on LEADER_NOT_AVAILABLE — leader elections are an expected, routine part of normal cluster operation, not evidence that something is broken by default. Whether that retry ever succeeds is what determines whether you have a real problem.
What's correlation id 7? Just a request/response sequence number the Kafka wire protocol uses to match a response to the request that triggered it. It isn't the cause of anything — ignore the number and look at the topic name in braces instead. If braces list more than one topic, that points toward a cluster-wide cause (a genuine leadership gap) rather than one misbehaving topic.
The benign case: right after topic creation
Creating a topic and electing a leader for each of its partitions are not instantaneous, and there's a small window between the topic existing and its leadership being fully propagated across the cluster. A produce or fetch request that lands in that window sees LEADER_NOT_AVAILABLE, and the client's built-in retry logic succeeds moments later once election finishes:
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 3
# a client sending immediately afterward may log ONE instance of:
# WARN ... Error while fetching metadata with correlation id 7 : {orders=LEADER_NOT_AVAILABLE}
#
# followed within a second or two by successful sends — no action needed
The signature that tells you this is the benign case: it appears once (or a handful of times) immediately after topic creation, then stops. If that's what you're seeing, there is nothing to fix.
This same race can show up even if you never ran --create yourself: with auto.create.topics.enable=true (the broker default in many setups), producing to a topic that doesn't exist yet creates it on the fly, and the very first request can land in the same just-in-time election window. It's mechanically identical to the case above — it just reads as "I never created a topic and got this error" instead.
If this window is a nuisance on a slow-electing cluster, the client-side metadata.max.age.ms setting controls how often the client proactively refreshes its metadata; lowering it shortens how long the client can keep using stale metadata before it learns a leader now exists.
Fix 1: if it repeats forever, check advertised.listeners
This is the dominant cause when the warning never resolves — especially in Docker or Kubernetes. The mechanism is subtle enough to be worth walking through carefully, because the symptom (bootstrap succeeds, everything after fails) is genuinely confusing the first time you hit it.
A Kafka client's connection has two steps. First it connects to a bootstrap address to ask "who is the leader for this partition?" That connection can succeed. The broker then replies with an address for the client to use for the actual partition leader — and that's the advertised.listeners value. If that address is a hostname that only resolves inside the Docker network the broker lives in, an external client can complete step one and then fail every subsequent request, because it's being told to connect somewhere it fundamentally cannot reach.
Client Broker (bootstrap: localhost:9092)
|----- 1. bootstrap connect -------->|
|<---- "leader for orders-0 is |
| advertised at kafka:9092" ---|
|
|----- 2. connect to kafka:9092 ----> X unresolvable outside
| the Docker network
|
'--> LEADER_NOT_AVAILABLE — repeats forever, every request
Step 1 succeeds because it uses the address you gave the client directly. Step 2 fails silently from the client's point of view — it just can't reach kafka:9092 — and every retry repeats the same doomed handoff, which is why the symptom looks like "connects fine, then nothing ever works."
# ❌ broker only advertises its internal Docker hostname
KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092
# a client on the host machine can reach the bootstrap port,
# but "kafka" doesn't resolve outside the Docker network —
# every request after the first fails the same way, forever
# ✅ two listeners: one for other containers, one for the host
KAFKA_LISTENERS=INTERNAL://0.0.0.0:9092,EXTERNAL://0.0.0.0:9093
KAFKA_ADVERTISED_LISTENERS=INTERNAL://kafka:9092,EXTERNAL://localhost:9093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME=INTERNAL
# docker-compose.yml — expose the external port to the host:
# ports:
# - "9093:9093"
Other containers on the same Docker network connect via kafka:9092 (the internal listener); anything outside that network — your host machine, a local script, a different compose project — connects via localhost:9093 (the external listener). Each listener advertises an address that's actually reachable from where its clients run. This is the single most common Kafka Docker misconfiguration, and it produces exactly the confusing "connects, then fails on everything" pattern this error describes.
Kubernetes: a related but distinct cause
In Kubernetes the same failure mode shows up for a different reason. A Kafka StatefulSet behind a headless service needs each broker pod to advertise its own address, not one value shared across the whole set:
# pod kafka-0 advertises its own stable headless-service hostname:
KAFKA_ADVERTISED_LISTENERS=INTERNAL://kafka-0.kafka-headless.default.svc.cluster.local:9092
# pod kafka-1 advertises a different one, derived from its own ordinal:
KAFKA_ADVERTISED_LISTENERS=INTERNAL://kafka-1.kafka-headless.default.svc.cluster.local:9092
# ❌ every pod advertising the same hardcoded hostname (or the
# StatefulSet's service name instead of each pod's own identity)
# routes clients to a leader address only some pods can reach
If Kafka is also exposed outside the cluster — via a LoadBalancer, NodePort, or Ingress — the same rule applies one layer further out: that external listener has to advertise the address external clients actually connect through (the load balancer hostname, or the node's external IP and mapped port), not the pod's internal cluster-local address.
Fix 2: confirm it isn't a genuine leadership gap
Outside of Docker listener issues, this can also mean a partition genuinely has no eligible leader — every replica is on a broker that's down, or unclean leader election is disabled and no in-sync replica remains:
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic orders
# a healthy partition shows a real leader id:
# Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,2,3
#
# a partition close to losing its leader shows a shrunk ISR:
# Partition: 0 Leader: none Replicas: 1,2,3 Isr: 2
# ^ only one in-sync replica left,
# and if that broker is also down,
# no leader can be elected
#
# the worse case — no in-sync replicas left at all:
# Partition: 0 Leader: none Replicas: 1,2,3 Isr:
# ^ every replica has fallen out of sync;
# recovery means either restarting one
# back into the ISR, or accepting data
# loss via unclean leader election
If Leader genuinely shows none, this is a cluster health problem, not a client configuration problem: check which brokers in Replicas are actually up, and whether unclean.leader.election.enable is deliberately set to false (the safer default, since enabling it can elect a leader with an incomplete log and lose acknowledged data). Bringing enough replicas back online resolves it; forcing unclean election is a data-loss trade-off, not a first response.
How to tell which problem you have
| Benign / listener misconfiguration | Genuine leadership gap | |
|---|---|---|
--describe shows | A real leader ID (the warning is stale or a client-reachability issue) | Leader: none |
| Pattern | Either stops after topic creation, or repeats forever from one specific client environment (Docker, another host) | Repeats from every client, everywhere |
| Fix | advertised.listeners, or just wait it out | Broker/replica health — bring brokers back up |
Verifying the fix worked
Don't just redeploy and hope the retries stop — prove it from the client's actual network, not from inside the broker's own container:
# run this from wherever the CLIENT actually runs, not the broker host:
kafka-broker-api-versions.sh --bootstrap-server <external-address>:9093
# kcat (kafkacat) is often quicker to reach for:
kcat -b <external-address>:9093 -L
# if the brokers it lists are addressed by something you can't resolve
# or reach from here (e.g. "kafka:9092" from outside Docker),
# advertised.listeners is still wrong — the config change didn't take
Both commands fail fast and clearly when an advertised address isn't reachable, instead of leaving you to infer it from another round of confusing client retries.
Debugging checklist
- ✓ Did the topic get created moments before the warning (explicitly, or implicitly via
auto.create.topics.enable)? It likely resolves on its own within seconds - ✓ Run
kafka-topics.sh --describe— isLeadera real broker ID, or literallynone? - ✓ If a real leader exists but the client still fails: check
advertised.listenersagainst where the client actually runs - ✓ Running in Docker? Confirm you have a separate internal and external listener, each advertising a reachable address
- ✓ Running in Kubernetes? Confirm each pod advertises its own headless-service hostname, and any external listener advertises the LoadBalancer/NodePort/Ingress address
- ✓ Does the error list one topic in braces, or several? Several points toward a cluster-wide cause rather than one misbehaving topic
- ✓ If
Leader: nonegenuinely, check which replica brokers are down and whether they can be restarted - ✓ Only consider
unclean.leader.election.enable=trueas a last resort — it can elect a leader with data loss - ✓ After changing
advertised.listeners, confirm it withkafka-broker-api-versions.shorkcat -Lfrom the client's own network before assuming it's fixed
Frequently Asked Questions
What does LEADER_NOT_AVAILABLE mean?
Every Kafka partition has exactly one leader replica that handles all reads and writes for it. LEADER_NOT_AVAILABLE means the client asked to produce to or fetch from a partition that currently has no elected leader, so the request cannot be served until a leader election completes.
Is LEADER_NOT_AVAILABLE always a real problem?
No — right after a topic is created, leadership assignment and propagation take a brief moment, and a request that arrives in that window will see this warning and then succeed automatically on retry a second or two later. Kafka clients retry it by default. If it appears once around topic creation and then stops, it's expected behaviour, not a bug.
Why does this error repeat forever instead of resolving itself?
In containerized setups this is almost always advertised.listeners. The initial bootstrap connection succeeds, but the broker then tells the client which address to use for the actual partition leader — and if that advertised address is an internal Docker hostname the client can't resolve, every subsequent request fails the same way, indefinitely, because the client keeps being pointed at an address it can never reach.
What is advertised.listeners and why does it matter?
listeners is the address the broker binds to internally; advertised.listeners is the address the broker tells clients to use when connecting. Inside a Docker network the broker might bind to 0.0.0.0:9092 while advertising kafka:9092 — a hostname that only resolves inside that same Docker network. A client running on the host machine or a different network can reach the bootstrap port but then fails on every subsequent request that relies on the advertised address.
How do I configure Kafka in Docker so external clients can connect?
Define two listeners — one for traffic inside the Docker network and one for traffic from the host or outside — and advertise a different, correctly resolvable address on each. The internal listener advertises the container's Docker network hostname; the external listener advertises localhost or the host's real address, mapped through the corresponding exposed port.
Can too few in-sync replicas cause LEADER_NOT_AVAILABLE?
Yes. If all replicas for a partition are on brokers that are down, or unclean leader election is disabled and no in-sync replica remains eligible, no leader can be elected and requests to that partition return LEADER_NOT_AVAILABLE until enough replicas recover. This is distinct from the listener misconfiguration case and points at genuine broker or cluster health rather than client configuration.
What does correlation id mean in a Kafka error message?
The correlation id is just a sequence number the Kafka wire protocol uses to match a response to the request that triggered it. It has no bearing on the cause of the error — the part that matters is the topic name listed in braces alongside it.
Can LEADER_NOT_AVAILABLE happen even if I never created the topic myself?
Yes. If auto.create.topics.enable is true, producing to a topic that doesn't exist yet creates it implicitly, and the very first request can race that just-in-time leader election the same way an explicit kafka-topics.sh --create would. It's mechanically the same benign case, just triggered without an explicit create step.
Why does LEADER_NOT_AVAILABLE happen in Kubernetes even with correct Docker-style listener config?
In a StatefulSet behind a headless service, each broker pod needs its own advertised.listeners value derived from its own stable pod hostname (e.g. kafka-0.kafka-headless.default.svc.cluster.local). A single shared advertised address can't work across a StatefulSet, since clients need to reach each pod individually. If you also expose Kafka outside the cluster via a LoadBalancer, NodePort, or Ingress, the external listener must advertise that externally reachable address instead.
More Kafka errors & guides
Browse the full error reference, or read the Kafka theory guides that explain the mechanisms behind these failures.