---
title: "OFFSET_NOT_AVAILABLE in Kafka: follower fetch and elections"
description: "Why a Kafka fetch or offset lookup gets OFFSET_NOT_AVAILABLE when a follower or a new leader is behind on the high watermark, and why the consumer just retries."
url: https://monedula.dev/kafka/troubleshooting/offset-not-available/
---

# OffsetNotAvailableException (OFFSET_NOT_AVAILABLE)

Kafka error · OFFSET_NOT_AVAILABLE · retriable.

Exception: `org.apache.kafka.common.errors.OffsetNotAvailableException`

## Quick answer

A broker answered with OFFSET_NOT_AVAILABLE (error code 78) because it does not yet know a high watermark that covers the offset asked for. With follower fetching (KIP-392) that is a follower a fetch round behind the leader; right after a leader election it is a new leader whose high watermark has not caught up. Both are short, and the client retries.

## What it means

Consumers only read records below the high watermark, the offset every in-sync replica has. The leader moves the high watermark as followers fetch, and a follower learns it only from the leader's answer to its next fetch, so a follower's high watermark trails the leader's. KIP-392 (Kafka 2.4) lets a consumer with client.rack read from an in-sync follower in its own rack when the brokers set replica.selector.class, for example to org.apache.kafka.common.replica.RackAwareReplicaSelector. The consumer's position may come from the leader: auto.offset.reset=latest looks up the leader's end offset, and a consumer may read from the leader before it is pointed at the follower. If that position is above the high watermark the follower knows but within its log, KIP-392 has the follower answer OFFSET_NOT_AVAILABLE rather than serve records it cannot vouch for. The second case is a leader election: until the new leader's high watermark reaches the start offset of its leader epoch, a request for the latest offset (ListOffsets) fails with OFFSET_NOT_AVAILABLE, the case the error's own description names: "The leader high watermark has not caught up from a recent leader election so the offsets cannot be guaranteed to be monotonically increasing." The consumer handles a fetch error like this one by logging "Error in fetch for partition orders-0: org.apache.kafka.common.errors.OffsetNotAvailableException" at DEBUG, requesting a metadata update and clearing its preferred read replica, so its next fetch goes to the leader, which names the follower again. No record is skipped or lost.

## Likely causes, most common first

1. **A follower reader is ahead of what its follower knows.** With replica.selector.class and client.rack set, the consumer fetches from a follower. A new consumer starting at latest, or one that read from the leader while its follower was out of the ISR, can hold a position the follower has not learned is committed yet. The gap is about one follower fetch round, so the error appears once or twice and then stops.
2. **The follower is slow to fetch.** A follower that fetches less often, or waits longer at the leader (replica.fetch.wait.max.ms, default 500 ms), learns each new high watermark later. If it stays in the ISR, it stays the preferred read replica, and a consumer that keeps catching up with the leader keeps meeting the gap.
3. **A leader election just happened.** A newly elected leader starts its epoch at its log end offset, and its high watermark can sit below that until the followers fetch from it. A ListOffsets request for the latest offset in that window, from a consumer resetting its position, kafka-get-offsets.sh or an admin client, gets OFFSET_NOT_AVAILABLE until the high watermark catches up.

## How to fix it

- Usually nothing: the client retries, and the error stops once the follower or the new leader learns the high watermark. It only needs a look when it repeats for minutes on the same partition.
- Check that the follower serving the rack is healthy and in sync: kafka-topics.sh --bootstrap-server localhost:9092 --describe --under-replicated-partitions lists partitions whose ISR is short, and the follower's fetch metrics show whether it keeps up.
- Check the rack names: a consumer's client.rack must match a broker.rack exactly, or the leader names itself as the preferred read replica and follower fetching never happens.
- For an admin script that lists offsets right after a failover, retry the request with a short backoff instead of failing the job.

## What not to do

- Turning follower fetching off because of DEBUG-level OFFSET_NOT_AVAILABLE entries: they are part of how it works, and leader reads cost cross-zone traffic again.
- Treating it like OFFSET_OUT_OF_RANGE: the offset is valid and the data is there, it is just not confirmed committed on that broker yet.

## Does the client retry it?

Yes, and the client does it for you. OffsetNotAvailableException is a RetriableException. A consumer that gets it on a fetch logs it at DEBUG, drops its preferred read replica, refreshes metadata and fetches again, first from the leader; an application normally never sees it.

## Configs involved

- [`replica.selector.class`](https://kafka.apache.org/44/configuration/broker-configs/#brokerconfigs_replica.selector.class): Since Kafka 2.4 (KIP-392), the class a leader uses to pick the replica a consumer reads from (default null, always the leader); org.apache.kafka.common.replica.RackAwareReplicaSelector picks an in-sync replica in the consumer's client.rack, which keeps reads inside one zone.
- [`client.rack`](https://kafka.apache.org/44/configuration/consumer-configs/#consumerconfigs_client.rack): The rack (in the cloud, the availability zone) the client runs in (default empty); with a broker-side replica.selector.class such as RackAwareReplicaSelector a consumer fetches from a follower in its own rack instead of the leader, and since Kafka 4.4 a producer with partitioner.rack.aware=true sends keyless records to partitions whose leader is in its rack.
- [`replica.fetch.wait.max.ms`](https://kafka.apache.org/44/configuration/broker-configs/#brokerconfigs_replica.fetch.wait.max.ms): How long a follower fetch request waits at the leader for new records (default 500 ms); keep it below replica.lag.time.max.ms so replicas of quiet partitions do not drop out of the ISR.

## Reproduce it in the simulator

- [Kafka KIP-392: consumers fetch from the closest replica](https://monedula.dev/kafka-simulator/scenarios/fetch-from-closest-replica/) (Fetch from the closest replica): [open at the moment it happens](https://monedula.dev/kafka-simulator/playground/?scenario=02.1.5&t=3)

## Sources

- [KIP-392: Allow consumers to fetch from closest replica](https://cwiki.apache.org/confluence/display/KAFKA/KIP-392%3A+Allow+consumers+to+fetch+from+closest+replica)
- [Apache Kafka 4.4.0 source: Errors.java (OFFSET_NOT_AVAILABLE, code 78)](https://github.com/apache/kafka/blob/4.4.0/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java)
- [Apache Kafka 4.4.0 source: OffsetNotAvailableException.java](https://github.com/apache/kafka/blob/4.4.0/clients/src/main/java/org/apache/kafka/common/errors/OffsetNotAvailableException.java)
- [Apache Kafka 4.4.0 source: FetchCollector.java (fetch error handling)](https://github.com/apache/kafka/blob/4.4.0/clients/src/main/java/org/apache/kafka/clients/consumer/internals/FetchCollector.java)
- [Apache Kafka 4.4.0 source: FetchUtils.java (requestMetadataUpdate clears the preferred read replica)](https://github.com/apache/kafka/blob/4.4.0/clients/src/main/java/org/apache/kafka/clients/consumer/internals/FetchUtils.java)
- [Apache Kafka 4.4.0 source: Partition.scala (ListOffsets while the high watermark lags the epoch start)](https://github.com/apache/kafka/blob/4.4.0/core/src/main/scala/kafka/cluster/Partition.scala)
- [Apache Kafka 4.4.0 source: RackAwareReplicaSelector.java](https://github.com/apache/kafka/blob/4.4.0/clients/src/main/java/org/apache/kafka/common/replica/RackAwareReplicaSelector.java)
- [Apache Kafka 4.4: broker config replica.selector.class](https://kafka.apache.org/44/configuration/broker-configs/#brokerconfigs_replica.selector.class)
- [Apache Kafka 4.4: consumer config client.rack](https://kafka.apache.org/44/configuration/consumer-configs/#consumerconfigs_client.rack)

## Related

- [OffsetOutOfRangeException in Kafka: causes and fixes](https://monedula.dev/kafka/troubleshooting/offset-out-of-range/)
- [Kafka under-replicated partitions: causes and fixes](https://monedula.dev/kafka/troubleshooting/under-replicated-partitions/)
