Rack Awareness & Multi-AZ Placement
Learn how Kafka rack awareness spreads replicas across racks and availability zones to survive datacenter-level failures.
Rack Awareness & Multi-AZ Placement is a free Apache Kafka & Stream Processing Fundamentals lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Apache Kafka & Stream Processing Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Rack Awareness?
Rack awareness tells Kafka about the physical (or cloud) topology of your brokers.
Without it, all replicas of a partition could land on brokers sharing the same rack or availability zone. If that zone fails, the partition becomes unavailable.
- Each broker advertises a
broker.rackvalue. - Kafka then places replicas on different racks when possible.
Configuring broker.rack
Set broker.rack in each broker's server.properties to identify its rack or zone.
# server.properties on a broker in us-east-1a
broker.id=1
broker.rack=us-east-1a
# Another broker in a different zone
broker.id=2
broker.rack=us-east-1bHow Replicas Get Spread
When a topic is created, Kafka's replica assignment algorithm alternates across racks.
For a partition with replication factor 3 and 3 racks, each replica lands on a distinct rack — guaranteeing the partition survives the loss of any single rack.
Cloud Availability Zones
In AWS, GCP, or Azure, map broker.rack to the availability zone (AZ).
- AZs are physically isolated within a region.
- Spreading replicas across AZs protects against a full AZ outage.
- Beware cross-AZ network costs for replication traffic.
Creating a Rack-Aware Topic
No special flag is needed — if brokers have broker.rack set, topic creation is automatically rack-aware.
kafka-topics.sh --create \
--bootstrap-server localhost:9092 \
--topic orders \
--partitions 6 \
--replication-factor 3Verifying Replica Placement
Use --describe to inspect which brokers hold each replica, then cross-check against broker racks.
kafka-topics.sh --describe \
--bootstrap-server localhost:9092 \
--topic ordersThe min.insync.replicas Tie-In
Rack awareness protects placement, but durability also depends on min.insync.replicas.
With replicas spread across 3 AZs and min.insync.replicas=2, a producer using acks=all can still write even if one entire AZ is down.
Follower Fetching from Closest Replica
Kafka 2.4+ supports fetch from follower. Consumers can read from a replica in their own rack, cutting cross-AZ traffic and latency.
# broker config
replica.selector.class=org.apache.kafka.common.replica.RackAwareReplicaSelector
# consumer config
client.rack=us-east-1aLimitations to Know
Rack awareness is best-effort:
- If racks < replication factor, some replicas share a rack.
- Reassignments triggered manually do not always respect racks unless you generate a rack-aware plan.
- It does not rebalance existing topics when you add
broker.racklater.
Generating a Rack-Aware Reassignment
To fix existing topics after enabling rack awareness, generate a reassignment plan with the reassign-partitions tool.
kafka-reassign-partitions.sh \
--bootstrap-server localhost:9092 \
--topics-to-move-json-file topics.json \
--broker-list 1,2,3 \
--generateDesign Checklist
Before going to production:
- Replication factor >= number of racks you want to tolerate losing + 1.
- Set
min.insync.replicasto at least 2. - Use
acks=allon critical producers. - Enable follower fetching to control cross-AZ costs.
Quick Check
Test your understanding of rack awareness.
Recap
You learned how rack awareness spreads replicas across racks and availability zones.
- Set
broker.rackper broker. - Topic creation becomes automatically rack-aware.
- Combine with
min.insync.replicasandacks=allfor AZ-failure resilience. - Use follower fetching to reduce cross-AZ cost.
Frequently asked questions
Is the “Rack Awareness & Multi-AZ Placement” lesson free?
Yes — the full text of “Rack Awareness & Multi-AZ Placement” is free to read here on the web, and the Apache Kafka & Stream Processing Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Apache Kafka & Stream Processing Fundamentals course, upgrade to CoddyKit PRO.
What will I learn in “Rack Awareness & Multi-AZ Placement”?
Learn how Kafka rack awareness spreads replicas across racks and availability zones to survive datacenter-level failures. You practise Apache Kafka & Stream Processing Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Apache Kafka & Stream Processing Fundamentals?
No prior experience is required. Apache Kafka & Stream Processing Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Rack Awareness & Multi-AZ Placement” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Apache Kafka & Stream Processing Fundamentals lesson?
Yes. Every Apache Kafka & Stream Processing Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Replication & Fault Tolerance
- Controller & ZooKeeper/Kraft Roles
- Designing a Kafka Cluster
- Rack Awareness & Multi-AZ Placement