Learn why Kafka’s LEADER_NOT_AVAILABLE error is often temporary, how partition leader elections affect message delivery, and how producer retries with backoff can help. A clear look at transient broker conditions—and why configuration or missing-topic issues need a different fix.

Multiple Choice

Which of the following errors is retriable from the Kafka Producer?

Retrial-worthy errors are those that reflect temporary conditions in the cluster that the producer can recover from by retrying with backoff. LEADER_NOT_AVAILABLE signals that the partition’s leader is currently not available—often due to an ongoing leader election or a brief broker issue. Since leadership can re-establish itself, retrying the send makes sense and is the correct approach. Invalid configuration is a client-side problem that won’t be solved by simply retrying; the producer needs the configuration fixed. Unknown topic or partition indicates a non-existent topic/partition, which isn’t a transient state you can resolve by retrying unless the topic is created first.

When Kafka Producers Should Retry—and When They Shouldn’t

A Kafka producer sends records to brokers that manage individual topic partitions. Most of the time, that path is straightforward: the producer finds the right broker, sends a record, and receives confirmation. But a Kafka cluster is a living system. Brokers can restart, partitions can change leaders, and metadata can briefly lag behind what’s happening in the cluster.

That’s why producers can retry certain failures. A retry gives Kafka a moment to recover and the producer a chance to send the record again. But retries aren’t a cure-all. They help with temporary conditions, not incorrect settings or resources that don’t exist.

A short pause can fix a leader problem

Each Kafka partition has a leader broker. The leader handles reads and writes for that partition, while other brokers may hold replicas. When a producer sends a record, it needs to reach the current leader.

Sometimes that leader is temporarily unavailable. A broker may be starting up, a partition may be undergoing a leader election, or the cluster may be handling a brief disruption. Kafka can report this condition as LEADER_NOT_AVAILABLE.

The key word is temporarily. A leader election is a normal part of cluster recovery: Kafka selects an eligible replica to take over, and the new leader resumes handling requests. If the producer retries after a short delay, the cluster may have already settled. The same send that failed moments ago can then succeed.

So LEADER_NOT_AVAILABLE is a retriable error. Retrying with a suitable delay is sensible because the underlying issue may resolve without anyone changing the producer’s configuration or creating new Kafka resources.

Retries need a little patience

A producer shouldn’t necessarily fire the same request again at full speed. If a broker is recovering, a rush of repeated requests can add pressure just when the cluster needs room to stabilize. Kafka’s retry settings help manage what happens after a request fails, while backoff adds a pause before another attempt.

In Java clients, settings such as retries, retry.backoff.ms, and delivery.timeout.ms shape this behavior. The exact settings depend on the Kafka client version and the application’s needs. A retry limit matters, but so does the total time the application is willing to wait for a record to be delivered.

Think of it like calling a busy office. Calling again a moment later may work; calling every fraction of a second just makes the line busier. A measured delay gives the system breathing room.

A retry also doesn’t mean success is guaranteed. If the broker remains unavailable, or the delivery deadline passes, the producer will eventually report a failure. The application should be ready to handle that outcome: log useful details, alert when failures persist, and decide what should happen to the affected record.

Temporary trouble and permanent problems are different beasts

The most useful way to reason about producer errors is to ask what would make the next attempt succeed.

If the answer is “time,” a retry may help. A leader election or brief broker interruption can fall into that category. The cluster may return to a healthy state while the producer waits.

If the answer is “someone must change something,” repeating the request is unlikely to help. For example, INVALID_CONFIGURATION points to a problem in the client’s settings. A malformed value, an unsupported combination, or another configuration issue won’t be repaired by sending the same request again. The setting needs attention.

Similarly, UNKNOWN_TOPIC_OR_PARTITION means the broker can’t find the topic or partition named in the request. If the topic hasn’t been created—or the name is wrong—retries alone won’t conjure it into existence. The resource must be created or the producer’s destination corrected. There can be timing details around newly created topics and metadata updates, but that doesn’t change the basic distinction: repeated sends aren’t a substitute for a valid destination.

This is a useful habit beyond Kafka, too. Before adding retries, identify whether the failure is transient or structural. Retrying a temporary outage is resilience. Retrying a bad configuration is just repetition.

What the producer does with metadata

Producers keep metadata about the cluster, including which broker leads each partition. That information can become stale when leadership changes. Kafka clients can refresh metadata and route later requests using the updated view.

This helps explain why leadership-related errors may clear after a short pause. The cluster’s state changes, and the producer can learn where to send the record next. Metadata refresh and request retries work together, though they aren’t the same thing: one updates the producer’s picture of the cluster, while the other gives a failed operation another chance.

It’s also why transient errors may appear during a broker event without meaning the whole system is broken. A brief burst of failures around a leader change can be expected. A sustained stream of them is different; it may point to an unhealthy broker, repeated elections, or a wider cluster problem.

Retries and duplicate records

Retries raise an important question: what if Kafka receives a record, but the acknowledgement gets lost? The producer may not know whether the broker wrote the record, so another attempt could, in some circumstances, result in a duplicate.

Kafka provides idempotent producer support to reduce this risk. With idempotence enabled, the producer can retry safely while Kafka uses producer identifiers and sequence numbers to prevent duplicate writes caused by those retries. Modern Kafka clients commonly enable idempotence by default, but teams should confirm the behavior for their client version and configuration.

Idempotence doesn’t make every application-level delivery guarantee automatic. For example, if an application restarts and independently sends the same business event again, that’s a separate issue. Still, for network and broker errors during a producer session, idempotence is an important part of reliable delivery.

How to read the signals

When producer errors occur, look at their pattern, not just one line in a log. A brief LEADER_NOT_AVAILABLE message during a broker transition may be routine. The same error repeating for several minutes deserves investigation.

Useful clues include the affected topic and partition, the timing of broker restarts, leader-election activity, producer timeout settings, and whether other partitions are also failing. Monitoring delivery latency and error rates can reveal whether retries are quietly recovering from a short disruption or masking a deeper issue.

And don’t set retry behavior in isolation. A long retry window can help an application ride through a short outage, but it can also delay reporting a genuine failure. A very short window can make transient cluster events look worse than they are. The right balance depends on how quickly the application needs an answer and what it can do when delivery fails.

The practical rule of thumb

A producer should retry when Kafka may be able to complete the same request after a brief pause. LEADER_NOT_AVAILABLE fits that pattern: leadership may be in transition, and a new leader can become available soon.

A producer shouldn’t rely on retries to fix invalid settings or create a missing topic. Those problems call for a configuration or resource change. In plain terms, retries are for temporary turbulence—not for a destination that was never there.

That distinction keeps Kafka applications both calmer and clearer. Retrying the right failures helps a producer recover gracefully; recognizing the rest helps engineers fix the actual cause instead of waiting for the same error to come around again.