๐ŸŽ‰ 75% of content is free forever โ€” Unlock Premium from $10/mo โ†’
CW
NEWSLIVESearch All Content
๐Ÿ’ผ Servicesโ„น๏ธ Aboutโœ‰๏ธ ContactView Pricing Plansfrom $10

Multi-Datacenter Kafka: MirrorMaker, Clusters and DR

Apache KafkaMulti-Datacenterโญ Premium

Multi-Datacenter Kafka: MirrorMaker, Clusters and DR

Senior level ยท Why a single stretch cluster fails, and how replication actually behaves across regions.

Prerequisites

  • !Kafka replication and ISR mechanics
  • !Broker listeners and security configuration

What You'll Learn

  • 1Explain why stretch clusters across regions degrade predictably
  • 2Choose between active-passive and active-active topologies
  • 3Configure MirrorMaker 2 with topic filters and offset translation
  • 4Plan a failover that does not lose or duplicate orders

Why one cluster cannot span two regions

A single Kafka cluster spread across datacenters is the design that looks cheapest and fails worst. Producers with acks=all wait for every in-sync replica, so a cross-region round trip of twenty to eighty milliseconds becomes the floor on every produce call. Raising linger.ms hides some of the latency but not all of it. Meanwhile a network blip between regions removes distant followers from the ISR, which does not reduce the latency floor for clients that still have a distant follower in sync.

The result is a cluster that is simultaneously slow for everyone and fragile during exactly the partition events you bought multi-region for. The community consensus is separate clusters per region, joined by an explicit replication layer, and the rest of this lesson assumes that shape.

TopologyWrite pathFailoverCost
Single stretch clusterCross-region on every produceAutomatic leadership moveLatency floor for all clients
Active-passiveLocal, replicated asyncPromote secondary, cut over clientsStandby idles; RTO measured in minutes
Active-activeLocal in both regionsRegional isolation; clients fail locallyConflict resolution becomes your problem
Hub-and-spokeLocal writes, hub mirrors allPeriphery fails to hubHub becomes a bottleneck and single point

Active-active is the right answer only when the two regions can partition cleanly: distinct topics or key spaces per region, or an application that can reconcile concurrent writes. Sharing one topic between regions with independent producers means two leaders accept writes for the same partition and MirrorMaker will happily carry both directions until the data is a mess that no offset can untangle.

MirrorMaker 2 as the replication layer

MirrorMaker 2 runs as a Connect cluster and mirrors topics, consumer offsets, consumer group state and ACLs between source and target. Offsets matter more than they sound: without translation, a consumer that fails over to the mirrored cluster starts at the wrong position and either redoes hours of work or skips records entirely.

# MM2 connector configuration
clusters=source,target
source.bootstrap.servers=kafka-east-1:9093,target.bootstrap.servers=kafka-west-1:9093

replication.policy.class=org.apache.kafka.connect.mirror.IdentityReplicationPolicy
# Steady-state production usually wants DefaultReplicationPolicy
# so mirrored topics keep a cluster prefix and never conflict locally.

topics=orders.,payments.
topics.exclude=.*\.internal\.|.*\.tmp\.
groups=orders-processor,payments-consumer
offset-syncs.topic.replication.factor=3
checkpoint.topic.replication.factor=3
sync.topic.acls.enabled=true
emit.checkpoints.interval.seconds=60
replication.policy.class=DefaultReplicationPolicy

Two details decide whether failover works. offset-syncs.topic carries the mapping between source and target offsets, so checkpointing must be frequent enough that a failover does not translate through an hour-old offset. And topics.exclude keeps internal and temporary topics off the wire; mirroring a Connect offset topic or a compacted internal topic across regions is how teams end up with replicated garbage that nobody can explain.

Filtering what crosses the region

# Steady-state: only tenant traffic, with the cluster prefix
source->target.topics=orders\..*
source->target.topics.exclude=orders\.scratch\..*

# During a failover drill, promote the mirror to writable by
# flipping the connector direction and updating client bootstrap lists

A topic mirrored both directions under the same name with two independent leaders is the classic active-active mistake. If you truly need bidirectional flow, isolate by key or by topic so the two directions never touch the same partition, and accept that the application owns ordering across the pair.

Failover without data loss or duplication

โš ๏ธAsync replication means the RPO is not zero

MirrorMaker replicates asynchronously. Between the last successful mirror and the failure, records written to the primary exist only there. Document that window, size it against business tolerance, and do not claim zero RPO in a design review unless you have measured it.
# 1. Confirm the mirror is current before declaring readiness
#    Check the last mirrored offset against the source log end

# 2. Stop producers writing to the failed region
#    (DNS cut, feature flag, or config rollout)

# 3. Promote consumers on the target region and verify group offsets
kafka-consumer-groups.sh --bootstrap-server kafka-west-1:9093 \
  --describe --group orders-processor

# 4. Re-point producers at the target and watch under-replicated partitions
kafka-topics.sh --bootstrap-server kafka-west-1:9093 \
  --describe --under-replicated-partitions

The order matters. Cutting producers first stops the primary from racing ahead of the mirror during the decision window. Promoting consumers second lets you confirm translated offsets before traffic resumes. Repointing producers last means the target region takes load only after both reads and lag look healthy.

Drill the procedure quarterly with a real DNS or config change rather than a tabletop exercise. The failures that show up are almost never in the replication layer; they are in the consumer that had a hardcoded bootstrap list, or the transactional id that still points at the dead region.

Latency budgets and what to promise

Cross-region produce with acks=all is at minimum one round trip plus ISR wait, so a twenty millisecond inter-region link sets a floor near forty milliseconds of produce latency. Async local writes with cross-region mirror put the replication lag in the order of the same round trip but keep local produce latency at single-digit milliseconds, and that is the trade most teams actually want.

Operating a multi-region cluster day to day

Multi-region Kafka fails differently from single-region Kafka, and the operational habits have to change with it. A single-region incident is usually a broker or a disk; a multi-region incident is usually the link between them, or a decision made under time pressure about which region is authoritative. The teams that handle this well have already made the decision in advance, documented which region owns writes for which topics, and drilled the cutover. The teams that struggle spend the incident debating topology while producers keep writing to the wrong side of a broken mirror.

The first operational rule is to monitor the mirror as a first-class component, not as an afterthought of the brokers. MirrorMaker lag, the age of the most recent checkpoint, and the gap between source and target log end offsets on mirrored topics are the three numbers that tell you whether the secondary region is actually current. A mirror that silently stopped hours ago looks identical to a healthy one on a broker-only dashboard; only the mirror's own metrics reveal the gap, and that gap becomes the recovery point objective the moment a failover starts.

The second rule is to keep the two regions independently operable. If a component in region one cannot function without a synchronous call to region two, then the design has quietly reintroduced the stretch-cluster problem through the application layer. Cross-region synchronous calls belong only where the business genuinely requires strong consistency across regions, which is rare; most workloads can tolerate eventual convergence through the mirror and prefer local availability over global consistency.

The third rule is to treat topology changes as migrations with their own rollback plan. Flipping a region from passive to active, changing a mirror's topic filter, or promoting a mirrored topic to a writable one are all changes that affect live traffic and that cannot be reverted with a config flip if they go wrong mid-cutover. Each should have a documented forward path, a documented rollback path, and a verification step that runs before traffic is moved, not after.

โš ๏ธDNS and client configuration are part of the failover path

A mirror can be perfectly current and failover can still take an hour because a consumer's bootstrap list points at a hostname that only resolves in the failed region, or because a service mesh routes cross-region traffic on a path that was never drilled. Include client configuration and DNS in the failover runbook and in the drill.

Common Mistakes

Spanning one Kafka cluster across two regions with acks=all

Fix: Run separate clusters per region with MirrorMaker between them. A stretch cluster makes every client pay cross-region latency and still fails over poorly.

Mirroring topics in both directions under the same name

Fix: Use a replication policy that prefixes cluster names, or isolate by topic so the two directions never write the same partition. Un-prefixed bidirectional mirrors converge into an unrecoverable mess.

Claiming zero RPO for an async mirror

Fix: Measure the actual replication lag and document the window. Zero RPO requires synchronous cross-region acks, which reintroduces the latency floor you were avoiding.

Never exercising failover because the design is sound

Fix: Drill quarterly with real client cutovers. Hardcoded bootstrap lists, stale ACLs and transactional ids all surface only under a live failover.

Best Practices

  • One cluster per region; never stretch a cluster across a high-latency link
  • Run MirrorMaker 2 as its own Connect cluster with dedicated topics for offsets and checkpoints
  • Tune checkpoint and offset-sync intervals against your RTO so translated offsets are fresh enough
  • Exclude internal, temporary and compacted system topics from the mirror by default
  • Keep regional write isolation for active-active: separate topics or key spaces, never shared partitions

Interview Questions

Q1: Why is a stretch Kafka cluster across regions a bad idea?

With acks=all every produce waits for a cross-region round trip, setting a latency floor for all clients. A network blip also drops distant followers from the ISR, so the cluster is both slower and still fragile.

Q2: What does MirrorMaker 2 replicate besides topic data?

Consumer offsets, consumer group state and ACLs, plus the offset-sync topic used to translate positions between clusters. Without offset translation, a failover consumer either redoes work or skips records.

Q3: How do you avoid conflicts in an active-active topology?

Isolate writes by topic or key so the two regions never lead the same partition, and put a replication policy in place that prefixes mirrored topic names. The application then owns any reconciliation across the pair.

Q4: What is the realistic RPO with MirrorMaker?

Async replication means the RPO equals the observed replication lag, typically on the order of the inter-region round trip plus mirror batch time. It is never zero unless you replicate synchronously.

Q5: Describe a safe failover sequence.

Confirm mirror currency, stop producers on the failed side, promote consumers on the target and verify translated offsets, then repoint producers and watch under-replicated partitions until the ISR recovers.

Key Takeaways

  • Separate clusters per region joined by an explicit mirror beat any stretch-cluster design on both latency and failure behavior
  • Active-active requires write isolation by topic or key, not just a bidirectional mirror
  • Mirror consumer offsets and group state, or failover consumers land at the wrong position
  • Async replication means a non-zero RPO you must measure and document
  • Failover is a drill, not a document; hardcoded bootstrap lists fail only under a live cutover
๐Ÿ”’

Premium Content

Multi-Datacenter Kafka: MirrorMaker, Clusters and DR

You've previewed the first section. Unlock this full lesson and 900+ advanced tutorials with a Premium plan.

๐ŸŽฏEnd-to-end Projects
๐Ÿ’ผInterview Prep
๐Ÿ“œCertificates
๐ŸคCommunity Access

Already a member? Log in

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-13

โ€”
โ˜†โ˜†โ˜†โ˜†โ˜†
0 ratings

Rate & Feedback

Advertisement