Rack awareness e distribuzione multi-AZ
Scopra come la rack awareness di Kafka distribuisca le repliche tra rack e zone di disponibilità per resistere ai guasti a livello di datacenter.
Rack awareness e distribuzione multi-AZ è una lezione Apache Kafka & Stream Processing Fundamentals gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Apache Kafka & Stream Processing Fundamentals, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Apache Kafka & Stream Processing Fundamentals include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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.
Domande Frequenti
La lezione «Rack awareness e distribuzione multi-AZ» è gratuita?
Sì — il testo completo di «Rack awareness e distribuzione multi-AZ» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Apache Kafka & Stream Processing Fundamentals, passa a CoddyKit PRO. Il corso Apache Kafka & Stream Processing Fundamentals include 4 lezioni in totale.
Cosa imparerò in «Rack awareness e distribuzione multi-AZ»?
Scopra come la rack awareness di Kafka distribuisca le repliche tra rack e zone di disponibilità per resistere ai guasti a livello di datacenter. Eserciti Apache Kafka & Stream Processing Fundamentals con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Apache Kafka & Stream Processing Fundamentals?
Non è richiesta alcuna esperienza precedente. Apache Kafka & Stream Processing Fundamentals su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Rack awareness e distribuzione multi-AZ»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Apache Kafka & Stream Processing Fundamentals?
Sì. Ogni lezione Apache Kafka & Stream Processing Fundamentals include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Replica e tolleranza ai guasti
- Ruoli di Controller e ZooKeeper/Kraft
- Progettazione di un cluster Kafka
- Rack awareness e distribuzione multi-AZ