---
title: "Kafka stretched cluster across three data centers"
description: "One Kafka cluster over three sites: rack-aware RF=3, min.insync.replicas=2 and a KRaft voter per site, what each write waits for, and losing a site."
url: https://monedula.dev/kafka/multi-dc/stretched-3-dc/
---

# Stretched cluster across three data centers

Checked against its sources on 29 November 2026.

A stretched cluster is one Kafka cluster whose brokers and KRaft controllers are spread over three data centers. With `broker.rack` set to the data center, a topic with replication factor 3 gets a replica in each, and `min.insync.replicas=2` with `acks=all` keeps every acknowledged record in at least two sites. Losing any one site then loses no acknowledged record and leaves a controller majority, and the price is a round trip to another site inside every write.

## Placing replicas and controllers

Kafka places replicas by rack, and a rack can be any failure domain, a data center included: set `broker.rack` on each broker to its site. When a topic is created or its replicas are reassigned, each partition spans min(racks, replication factor) racks, so a replication factor of 3 over three sites puts one replica in each. The Apache Kafka docs advise an equal number of brokers per rack: with uneven racks, the racks with fewer brokers get more replicas and do more of the replication work.

The controllers decide leadership and keep the cluster’s metadata, and they stay available only while a majority of them is alive: 3 controllers tolerate 1 failure and 5 tolerate 2, since withstanding N concurrent failures takes 2N + 1. With one controller in each site, losing any site leaves 2 of 3. With five, Confluent’s example places two, two and one, and losing any one site leaves at least 3 of 5. For critical deployments the Apache Kafka docs advise servers that run as a broker or as a controller, not both (`process.roles`).

With `min.insync.replicas=2` and `acks=all`, a write succeeds only while at least two replicas are in sync, the leader included. With one replica per site, those two are always in two different sites, which is what makes the RPO zero when one site is lost.

- Simulator: [Stretched 3-DC](https://monedula.dev/kafka-simulator/scenarios/stretched-3-dc/): Three data centers with a broker and a KRaft controller in each, and `orders` at RF=3 with `min.insync.replicas=2`.

## What every write waits for

A write to a Kafka partition is committed only when every in-sync replica has it, and with `acks=all` the producer waits for that: if all three replicas are in sync, all three must acknowledge, even though `min.insync.replicas` is 2. So while the ISR spans the three sites, every acknowledged write includes a round trip from the leader’s site to the slower of the other two. Records also become visible to consumers only once every in-sync replica has them and the ISR has at least `min.insync.replicas` members, whatever the producer’s `acks`.

A follower that has sent no fetch, or has not caught up to the leader’s log end offset, for `replica.lag.time.max.ms` (30 seconds by default) is removed from the ISR, and writes then wait only for the replicas left in it. With `min.insync.replicas=2` that still includes one other site. The number to measure is the round trip between your sites and the produce latency at the 99th percentile with `acks=all`, against a topic whose replicas span them.

## Reading from the nearest replica

By default a consumer fetches from the partition leader, so a consumer in one site reads across sites for every partition led elsewhere. KIP-392 lets consumers fetch from the closest replica to cut that cross-site traffic. On the brokers, `replica.selector.class` names the selector, by default one that returns the leader; `org.apache.kafka.common.replica.RackAwareReplicaSelector` picks a replica whose rack matches the consumer’s `client.rack`, which corresponds to the brokers’ `broker.rack`. A follower returns only committed records, but it learns the high watermark from the leader, so KIP-392 says follower fetching may have higher latency.

## Losing or cutting off one data center

When a site goes down, its brokers stop sending heartbeats to the controller, which considers a broker offline once no heartbeat has arrived for `broker.session.timeout.ms`, 9 seconds by default; heartbeats go every `broker.heartbeat.interval.ms`, 2 seconds by default. Once a lost broker’s session expires, the controller elects a new leader from the remaining in-sync replicas for each partition that broker led. The two remaining controllers are a majority, so elections and metadata changes continue, and the ISR of each partition shrinks to two replicas in two sites, which still meets `min.insync.replicas=2`, so `acks=all` writes go on.

Losing a second site also loses the controller majority: one controller of three cannot keep the metadata quorum available, so no new leader is elected and no ISR shrinks, and partitions led from a lost site stay without a leader. Even with a quorum, an ISR of one would be below `min.insync.replicas=2`, and `acks=all` producers would get `NotEnoughReplicas`. With `unclean.leader.election.enable` at its default `false`, Kafka does not elect a replica that may lack committed records, so those partitions wait for a site to return.

A site cut off by the network, rather than down, is decided by the controller majority too: the controller in the isolated site is one of three, so the other two sites keep the quorum and go on electing leaders and changing the metadata. The isolated site’s brokers cannot heartbeat to that majority, so once their sessions expire the controller considers them offline and elects leaders for their partitions in the other two sites.

- Simulator: [Stretched 3-DC](https://monedula.dev/kafka-simulator/scenarios/stretched-3-dc/): Isolate one data center: the other two keep a 2-of-3 controller majority, so leader elections go on, and the cluster is whole again after the network heals.

## Sources

- [Apache Kafka 4.3 docs, Balancing replicas across racks](https://kafka.apache.org/43/operations/basic-kafka-operations/#balancing-replicas-across-racks)
- [Apache Kafka 4.3 docs, KRaft: deploying considerations](https://kafka.apache.org/43/operations/kraft/#deploying-considerations)
- [Confluent Platform docs, Configure Multi-Region Clusters](https://docs.confluent.io/platform/current/multi-dc-deployments/multi-region.html)
- [Apache Kafka 4.3 docs, Design: Replication](https://kafka.apache.org/43/design/design/#replication)
- [Apache Kafka 4.3 docs, topic config min.insync.replicas](https://kafka.apache.org/43/configuration/topic-configs/#topicconfigs_min.insync.replicas)
- [Apache Kafka 4.3 docs, broker config replica.lag.time.max.ms](https://kafka.apache.org/43/configuration/broker-configs/#brokerconfigs_replica.lag.time.max.ms)
- [Apache Kafka 4.3 docs, broker config replica.selector.class](https://kafka.apache.org/43/configuration/broker-configs/#brokerconfigs_replica.selector.class)
- [Apache Kafka 4.3 docs, consumer config client.rack](https://kafka.apache.org/43/configuration/consumer-configs/#consumerconfigs_client.rack)
- [KIP-392: Allow consumers to fetch from closest replica](https://cwiki.apache.org/confluence/display/KAFKA/KIP-392%3A+Allow+consumers+to+fetch+from+closest+replica)
- [Apache Kafka 4.3 docs, broker config broker.session.timeout.ms](https://kafka.apache.org/43/configuration/broker-configs/#brokerconfigs_broker.session.timeout.ms)
- [Apache Kafka 4.3 docs, Design: Replication (node liveness)](https://kafka.apache.org/43/design/design/#replication)
- [Apache Kafka 4.3 docs, topic config unclean.leader.election.enable](https://kafka.apache.org/43/configuration/topic-configs/#topicconfigs_unclean.leader.election.enable)

## Changes to this page

- 29 November 2026: First published: placing replicas and controllers, what every write waits for, reading from the nearest replica, and losing or cutting off one site.
