On this page
Kafka Improvement Proposal
KIP-392: consumers read from the closest replica
KIP-392 lets a Kafka consumer read from a follower replica in its own rack or availability zone instead of always from the partition leader. In the cloud that removes most of the cross-zone traffic consumers cause, which is billed. It needs a replica selector on the brokers and client.rack on the consumer.
- Proposal
- KIP-392, Allow consumers to fetch from closest replica
- Status
- Shipped Since Kafka 2.4 (2019), opt-in with replica.selector.class and client.rack.
- Area
- Consumer groups and queues
- Proposal page
- KIP-392 on the Apache Kafka wiki
Why it was needed
Before KIP-392 every fetch went to the leader. With leaders spread over three zones, about two thirds of all consumer traffic crossed a zone boundary, and in a multi-datacenter cluster consumers read across the WAN even when a full copy sat next to them.
What it changes
The consumer sends its client.rack with each fetch. If the broker has a replica selector configured, the leader answers with a preferred read replica: an in-sync replica in the same rack, or itself if there is none. The consumer then fetches from that follower. A follower learns the high watermark only through replication, so new records reach follower readers a little later than leader readers.
How to use it
- Set broker.rack on every broker and replica.selector.class to the rack-aware selector on the brokers.
- Set client.rack on each consumer to the zone it runs in.
Where it stands
Shipped in Kafka 2.4 and widely used on cloud clusters. An offset the follower cannot serve yet returns OFFSET_NOT_AVAILABLE and the consumer retries, so reads stay correct.
What comes next
Stable. Producers got the matching feature much later with rack-aware partitioning (KIP-1123, Kafka 4.4), and diskless topics (KIP-1150) aim at the replication traffic neither of them removes.
See it in the simulator
- Kafka KIP-392: consumers fetch from the closest replica (Fetch from the closest replica) Step 3: Read from the follower in az-b Open at this step: Kafka KIP-392: consumers fetch from the closest replica
- Diskless vs classic Kafka: cross-AZ replication traffic (No replication across AZs) Step 4: The classic read crosses too Open at this step: Diskless vs classic Kafka: cross-AZ replication traffic
- Diskless vs classic Kafka: cross-AZ replication traffic (No replication across AZs) Step 2: Both batches land in az-a Open at this step: Diskless vs classic Kafka: cross-AZ replication traffic
The simulator asks for the preferred read replica on every fetch, so a consumer goes back to its follower as soon as that follower is in sync again, and after OFFSET_NOT_AVAILABLE it retries the same follower. A Kafka consumer keeps the replica the leader named until a fetch error or its next metadata refresh (metadata.max.age.ms, 5 minutes by default), and after an error it asks the leader again. The diskless scenario keeps the default selector and shows the cross-zone leader read that KIP-392 avoids.