What is the broker.rack configuration in Kafka, and what does setting it actually do?
answer
- per-broker string label = rack/AZ
- spreads replicas across racks
- survive one rack/AZ failure
- just a tag, Kafka doesn't validate
- set on ALL brokers
basics
~20 sbroker.rack is a per-broker string tagging which rack or availability zone a broker is in. Kafka uses these tags to spread a partition's replicas across different racks, so one rack failing doesn't take down all copies.
solid answer
~40 sbroker.rack is a per-broker config (e.g. broker.rack=us-east-1a) that labels the broker's physical rack or cloud availability zone. When set on all brokers, Kafka's rack-aware replica assignment tries to place each partition's replicas in as many distinct racks as possible. The goal is fault isolation: if an entire rack or AZ goes down, every partition should still have at least one surviving replica, so leadership can move and no data is lost. It takes effect during automatic topic creation, partition reassignment, and the kafka-topics CLI. It's just a label — Kafka doesn't validate it against real topology; you must set it correctly to match your physical/cloud layout.
go deeper
Know it's a per-broker label for rack/AZ that makes Kafka spread replicas across racks to survive a rack failure.
Know it's all-or-nothing across brokers, only affects new placements, and is just a label Kafka doesn't validate.
Tie it to AZ mapping in cloud, RF vs rack count math, and that it's the prerequisite for both fault isolation and KIP-392 follower reads.
Reason about topology design, mixed-config fallback behavior, and operational migration of existing topics into rack-aware layout.
## What broker.rack is `broker.rack` is a string configuration property you set in each broker's `server.properties` (or via dynamic config). It names the failure domain the broker lives in — typically a physical server rack in a data center, or a cloud **Availability Zone (AZ)** like `us-east-1a`. Example: `broker.rack=us-east-1a`. A **replica** is one copy of a partition's data. Every Kafka partition has a configurable **replication factor** (RF) — e.g. RF=3 means three brokers each hold a full copy: one **leader** (handles reads/writes) and two **followers** (continuously replicate from the leader). ## What it does When `broker.rack` is set on all brokers, Kafka switches to **rack-aware replica assignment**. Instead of just round-robining replicas across brokers, the assignment algorithm tries to spread a partition's RF replicas across as many *distinct racks* as possible. With RF=3 and 3 racks, each replica lands in a different rack. This is **fault isolation**: if one whole rack/AZ fails, every partition still has ≥1 surviving replica, leadership fails over to a survivor, and you lose no data and (usually) no availability. ## When it takes effect Rack-aware placement runs at: automatic topic creation, the `kafka-topics.sh --create` CLI, and partition reassignment (`kafka-reassign-partitions.sh`) when you let Kafka generate the assignment. It does **not** retroactively move replicas of topics that already exist — you must reassign them. ## Important caveats - It's **just a label**. Kafka does not verify it matches real topology. If you mislabel brokers, you get a false sense of safety. - **All-or-nothing**: if *some* brokers set `broker.rack` and others don't, by default Kafka refuses rack-aware assignment and falls back to non-rack-aware (controlled by whether you let it tolerate mixed config). Set it on every broker. - It enables, but is independent from, **fetch-from-follower** (KIP-392), which uses rack info on the *client* side to reduce cross-AZ network cost. ## Why it matters in the cloud Cross-AZ traffic costs money and adds latency, and AZ-wide outages happen. Mapping `broker.rack` to AZs gives you both an availability guarantee (survive an AZ loss) and the foundation for cost-saving follower reads.
- Does setting broker.rack rebalance replicas of topics that already exist?No. It only affects new placement decisions — topic creation and reassignment. Existing topics keep their current layout until you explicitly run a partition reassignment.
- What happens if only some brokers have broker.rack set?By default Kafka treats the cluster as having incomplete rack info and falls back to non-rack-aware assignment (it won't silently place some replicas rack-aware and others not). Set it on every broker for consistent behavior.
saying these in an interview costs you the question
- Saying broker.rack physically moves data or validates real topology — it's just a label.
- Claiming it automatically rebalances existing topics.
- Confusing broker.rack (server-side placement) with client rack config for follower fetching.