Video in progress
What does rack awareness (`broker.rack`, `client.rack`) give you in Kafka?
If broker.rack is set, Kafka places a partition's replicas in different racks or zones, so even if one zone goes down, each partition still has a copy. With client.rack and the rack-aware selector on the broker, a consumer can read from a follower in its own zone and cross-AZ traffic drops.
📖 Answer
In the cloud, 6 brokers across 3 zones. Without broker.rack, Kafka distributes replicas by broker ID, and all three copies of a partition with RF=3 can end up in just two zones. One zone goes down, the partition's ISR falls below min ISR, and writes stop.
# each broker gets its own zone
broker.rack=eu-central-1a
Now when a topic is created, replicas are spread across zones. Important: this applies at creation (or reassignment) time; to change existing topics you need a reassignment.
The second part is follower fetching (since Kafka 2.4):
# broker
replica.selector.class=org.apache.kafka.common.replica.RackAwareReplicaSelector
# consumer
client.rack=eu-central-1a
Normally a consumer reads only from the leader. If the leader is in another zone, every byte crosses zones, and the cloud provider charges for that. With follower fetching, the consumer reads from a replica in its own zone. The cost is slightly higher latency, because the follower is a little behind the leader.
Producers still write to the leader; that doesn't change. In Kubernetes you should take client.rack from the zone the pod is running in (through a node label); a hand-written value goes wrong when the pod moves to another zone.
Sign up to mark studied questions and save your progress.