Quick revision
The short answer
broker.rack labels each broker with its failure domain, such as an availability zone, and when a topic is created Kafka spreads each partition's replicas across different racks so one rack failure cannot take all of them. It applies at creation and in generated reassignments, not to existing replicas when the label is added later. With replica.selector.class set to RackAwareReplicaSelector on brokers and client.rack on consumers, a consumer can fetch from a follower in its own zone (KIP-392), while producers still write to leaders.
What to remember
In this answer, we saw that broker.rack labels brokers with their failure domain so that each partition's replicas are spread across zones when topics are created or reassignments are generated, but existing replicas do not move on their own. With RackAwareReplicaSelector on brokers and client.rack on consumers, consumers read from a same-zone follower, saving cross-zone traffic at the cost of slightly higher end-to-end latency, while producers keep writing to leaders.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
broker.rack labels each broker with its failure domain, such as an availability zone, and when a topic is created Kafka spreads each partition's replicas across different racks so one rack failure cannot take all of them. It applies at creation and in generated reassignments, not to existing replicas when the label is added later. With replica.selector.class set to RackAwareReplicaSelector on brokers and client.rack on consumers, a consumer can fetch from a follower in its own zone (KIP-392), while producers still write to leaders.
Why this question is asked
In the cloud, a Kafka cluster usually spans three availability zones, and two physical facts matter: a whole zone can fail, and traffic between zones costs money and adds latency. Kafka has settings for both, and interviewers ask about them because getting them wrong either loses data in a zone outage or quietly doubles the network bill. In this answer, we will recap replicas and leaders, see how broker.rack changes replica placement, look at its limits, and then see how consumers read from a nearby follower and what that costs.
1A Quick Recap of Replicas and Leaders
Each partition has several copies called replicas, three with replication factor 3. One replica is the leader: producers write to it, and by default consumers read from it. The others are followers, which fetch new records from the leader to stay in sync. If the leader's broker fails, one of the in-sync followers becomes the new leader.
That protection only works if the copies do not share a failure. If all three replicas of a partition sit on brokers in the same zone, losing that zone loses the partition, no matter how many replicas it has.
2What broker.rack Does at Topic Creation
broker.rack is a label we set in each broker's configuration. Kafka does not interpret the value; it only compares labels. When a topic is created, the assignment algorithm places the replicas of each partition on brokers with different rack labels, as far as the number of racks allows, and still spreads leaders evenly.
Notice that each partition has one replica per zone, so losing a zone leaves two in-sync copies, and with min.insync.replicas=2 producers using acks=all keep working.
3The Limits: Creation and Reassignment Only
Rack awareness is applied when Kafka chooses an assignment: at topic creation, when partitions are added, and when we generate a reassignment with kafka-reassign-partitions.sh --generate. It is not a background process. If a cluster ran for years without broker.rack and we add the labels now, every existing partition keeps its old replicas, even those with two copies in the same zone. Moving them requires an explicit reassignment.
Also, Kafka does not stop us from creating a manual assignment that ignores racks. Tools and reviews have to catch that.
4Reading From a Follower in the Same Zone
By default, consumers fetch from the leader. With three zones and leaders spread evenly, about two thirds of every consumer's reads cross a zone boundary. KIP-392 added follower fetching: the broker can tell a consumer to read from a different replica, and a rack-aware selector picks one in the consumer's own rack.
5 messages in order. Play them, or step through them one at a time.
The consumer still sends its first fetch to the leader. The leader sees client.rack, finds a replica on a broker with a matching broker.rack, and answers with a 'preferred read replica'. The consumer then fetches from that follower until something changes, such as the follower falling out of sync.
5What It Costs and What It Does Not Change
Producers always write to the leader; follower fetching only affects reads. And a follower serves records only up to the high watermark, the offset that all in-sync replicas have confirmed, as far as that follower knows it. The follower learns the high watermark from its own fetches to the leader, so it lags slightly behind. End-to-end latency from producer to consumer can therefore rise by a few milliseconds, usually a fair trade for removing cross-zone read traffic.
Assignment can help too. Recent clients can assign partitions rack-aware (for example the range and cooperative-sticky assignors with client.rack, and support in the newer consumer group protocol; check your version), so a consumer gets partitions that have a replica in its zone. Without that, a consumer may be assigned a partition with no replica in its zone and still read across zones.
6Follow-up questions
Does broker.rack protect the KRaft controllers too?
No. broker.rack affects partition replica placement. The controller quorum is placed by where we run the controller nodes, so we put them in different zones ourselves, for example three controllers in three zones.
What happens if the same-zone follower falls out of sync?
The consumer gets an error from the follower or is told to go back to the leader, and it refetches metadata and continues from the leader or another eligible replica. Reads continue; they just cross zones again for a while.
7Conclusion
In this answer, we saw that broker.rack labels brokers with their failure domain so that each partition's replicas are spread across zones when topics are created or reassignments are generated, but existing replicas do not move on their own. With RackAwareReplicaSelector on brokers and client.rack on consumers, consumers read from a same-zone follower, saving cross-zone traffic at the cost of slightly higher end-to-end latency, while producers keep writing to leaders.
Open with
broker.rack is just a label on each broker for its failure domain, usually the availability zone. Kafka uses it when it decides where replicas go: at topic creation, when partitions are added and when we generate a reassignment, it spreads each partition's replicas across different rack labels.
Then, if they want more
With three zones and replication factor 3, every partition gets one replica per zone, so losing a zone still leaves two in-sync copies, and with min.insync.replicas of 2 acks=all producers keep going. One thing people miss is that it is not retroactive. If you add the labels to an existing cluster, nothing moves; you have to run a reassignment.
The second part is follower fetching from KIP-392. On the brokers you set replica.selector.class to RackAwareReplicaSelector, and each consumer sets client.rack to its zone. The consumer's first fetch goes to the leader, the leader sees the client's rack and tells it to read from a replica in the same zone, and from then on it fetches from that follower.
That removes most cross-zone read traffic, which is a real cost saving. Producers still write to the leader, and followers only serve up to the high watermark they know about, so end-to-end latency goes up a little. Newer clients can also make partition assignment rack-aware so consumers get partitions that have a local replica.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What does broker.rack do in Kafka? Explain how it affects replica placement when a topic...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-internals/ffa75b5a88/