Cross-Datacenter Replication Use Cases in Kafka
Why would anyone copy a Kafka cluster into another building, city, or continent? Learn the real reasons, from disaster recovery to local reads, from legal rules to cloud migration, and see which design fits which problem.
Imagine a bakery with a single oven. The bread is wonderful, and customers love it. Then one morning the oven breaks. No oven means no bread, no bread means no sales, and the whole business stops until someone repairs it. A wise baker thinks about this early. Maybe she buys a second oven in another shop across town. Maybe she opens several shops so that every neighborhood has fresh bread close by. Maybe she keeps a written copy of every recipe in a safe deposit box, just in case.
Kafka teams face the same question. One Kafka cluster sits in one datacenter. That datacenter can lose power, lose its network, flood, or simply be far from many of your users. Copying data from one cluster to another, in a different datacenter, is called cross-datacenter replication. It is one of the most discussed topics in the Kafka world, because the reasons for doing it are many, and each reason leads to a different design.
This guide walks through those reasons, called use cases, one by one. For each, you will see what problem it solves, how the data moves, what can go wrong, and how to decide. We will also meet the tools that do the copying, and the traps that catch beginners.
Cross-datacenter replication means continuously copying topics, and often consumer positions, from a Kafka cluster in one location to a cluster in another. The main use cases are disaster recovery, serving users from a nearby copy, collecting data from many sites into one place, active-active operation, meeting data location laws, cloud migration and hybrid cloud, safe upgrades, and sharing data with other teams or companies.
Why One Datacenter Is Never Enough
A single location is a single point of failure, a single point of distance, and a single point of law.
Three kinds of trouble
Keeping everything in one place is simple, and simple is good. But three kinds of trouble appear as a business grows.
- Failure. A datacenter can go dark. Causes include a power cut, a cooling failure, a fire, a fiber cable cut by a digging machine, or a mistake during maintenance. When it goes dark, everything inside goes with it.
- Distance. Signals travel fast, but not instantly. A user in Mumbai talking to a server in Virginia waits much longer than one talking to a server in Mumbai. For some applications, that delay hurts.
- Rules. Some countries and industries require that certain data stays inside a border, or that a second copy exists somewhere else. A single cluster cannot satisfy both at once.
Think of a library with one building. If it floods, every book is lost. If you live far away, borrowing a book takes a long trip. If a law says local history must stay in the local town, you cannot ship it to the capital. A library system with several branches and shared catalogs solves all three problems. Cross-datacenter replication is the branch system for your data.
Why not just add more brokers?
A natural question is why a bigger cluster is not enough. Adding brokers inside one datacenter helps with load and with single-machine failures. It does nothing if the whole building is lost. Kafka does replicate each partition to several brokers, but if all of them sit in the same room, they all share the same fate.
The Vocabulary You Need First
A handful of words appear in every conversation about multi-datacenter Kafka. Learn them once.
| Term | Plain meaning | Everyday picture |
|---|---|---|
| Datacenter | A building, or a cloud region, full of servers | One branch of the library |
| Cluster | A group of Kafka brokers working as one system | The staff of one branch |
| Source cluster | The cluster data is copied from | The original book |
| Target cluster | The cluster data is copied to | The photocopy |
| Replication (inside a cluster) | Followers copying a partition from its leader | Two clerks in one room keeping the same ledger |
| Mirroring (across clusters) | A separate program copying topics between clusters | A courier carrying copies between branches |
| Active-passive | One cluster serves users, another waits as a backup | A spare oven kept switched off |
| Active-active | Both clusters serve users at the same time | Two shops, both selling bread |
| Failover | Switching users to the backup after a failure | Moving customers to the second shop |
| Failback | Returning to the original after it recovers | Moving back once the oven is repaired |
| RPO | Recovery Point Objective: how much data you can afford to lose, measured in time | “We can lose at most five minutes of orders” |
| RTO | Recovery Time Objective: how long you can afford to be down | “We must be selling again within thirty minutes” |
| Offset | A message’s position number in a partition | A page number |
The words replication and mirroring are often used loosely. In this guide, replication inside one cluster is done by Kafka itself, while copying between clusters is done by an extra tool sitting outside the two clusters.
Inside a Cluster Versus Across Clusters
Kafka already copies data. So why is a second kind of copying needed?
What Kafka does by itself
Every partition in Kafka has one leader and, usually, two followers. The followers constantly pull new messages from the leader. When a producer sends a message and asks for strong safety, Kafka waits until enough followers have the message before saying “done”. If the leader machine dies, a follower takes over. This all happens inside one cluster, over a fast local network, and it is automatic.
Why that is not enough
All those brokers belong to one cluster with one controller and one set of metadata. If the datacenter is lost, the whole cluster is lost. A second, separate cluster in another location has its own brokers, its own metadata, and its own life. Something must carry data from the first to the second. Kafka does not do this on its own between separate clusters, so we add a tool for it.
flowchart LR
subgraph DC1["Datacenter one"]
L1["Leader"] --> F1["Follower A"]
L1 --> F2["Follower B"]
end
subgraph DC2["Datacenter two"]
M1["Mirror tool"] --> L2["Leader"]
L2 --> F3["Follower A"]
L2 --> F4["Follower B"]
end
L1 -->|"read by"| M1
In the picture, each datacenter has its own leader and followers. The mirror tool reads from the first cluster like an ordinary consumer, and writes into the second cluster like an ordinary producer. Because it behaves like a normal client, the two clusters do not need to be the same size, the same version, or even in the same kind of environment.
The Basic Shapes of Multi-Datacenter Kafka
Almost every real design is one of a few shapes, or a mix of them.
Active-passive
One cluster does all the work. The other quietly receives copies and waits for an emergency.
Active-active
Both clusters accept writes from local applications, and each copies to the other.
Hub and spoke
Many small clusters send data to one big central cluster, or the reverse.
Stretched cluster
One single cluster whose brokers live in several nearby datacenters.
flowchart TB
subgraph AP["Active-passive"]
A1["Cluster A: serves users"] -->|"copies"| A2["Cluster B: standby"]
end
subgraph AA["Active-active"]
B1["Cluster A"] |"copies both ways"| B2["Cluster B"]
end
subgraph HS["Hub and spoke"]
S1["Site 1"] --> H["Central hub"]
S2["Site 2"] --> H
S3["Site 3"] --> H
end
The first three shapes use separate clusters and a mirroring tool. The fourth is different: it is a single cluster stretched across sites. We will compare them carefully later. For now, notice that every use case in this guide is really a choice of shape, made to solve one specific problem.
Active-passive is a spare tire in the trunk: unused until needed. Active-active is a car with four working tires, all sharing the load. Hub and spoke is like many small post offices sending mail to one big sorting center. A stretched cluster is like one huge post office with counters in several towns.
RPO and RTO: The Two Numbers Behind Every Decision
Before choosing a design, ask two questions: how much can we lose, and how long can we wait?
RPO: how much data can we lose?
Mirroring between clusters normally happens after a message has already been written in the source cluster. This is called asynchronous copying. There is always a small delay before the copy arrives. If the source datacenter dies at that exact moment, the messages still in transit are lost. The Recovery Point Objective is the amount of such loss you accept. A bank might accept almost none. A page-view counter might accept several minutes.
RTO: how long can we be down?
The Recovery Time Objective is the time between the disaster and the moment users are served again. If switching to the backup needs a human to wake up, read a checklist, and change many settings, the RTO is long. If applications switch automatically, it is short.
Last good copy
The final message that reached the backup before the failure. Everything after it is at risk. The gap is your data loss.
Disaster strikes
The primary datacenter becomes unreachable.
Detection and decision
Monitoring notices, and someone or something decides to fail over. This step is often the slowest.
Switch and resume
Applications point to the backup and continue reading from the right position. The time from step 2 to here is your recovery time.
| Business type | Typical attitude to loss | Typical attitude to downtime |
|---|---|---|
| Payments | Almost zero loss | Minutes at most |
| Online shop orders | Very little loss | Minutes to an hour |
| Analytics and reports | Some loss acceptable | Hours acceptable |
| Click and page-view tracking | Small loss acceptable | Often flexible |
Promising zero data loss and zero downtime is expensive and sometimes impossible with simple asynchronous mirroring. Always write your RPO and RTO down as numbers and let them guide the design, not the other way around.
Use Case One: Disaster Recovery
The classic reason: if the main site is lost, keep the business alive from another one.
The problem
Your company runs orders, payments, or shipping events through Kafka. If the cluster disappears, those flows stop, and worse, the history stored in the topics may vanish too. You need a second location holding a recent copy of the data, ready to take over.
The solution
Build an active-passive setup. The primary cluster serves everyone. A mirroring tool continuously copies chosen topics to a standby cluster in a distant location. Nobody reads from the standby during normal times. When disaster comes, applications are pointed at the standby, which already holds nearly all the data.
flowchart LR
P["Producers"] --> C1["Primary cluster"]
C1 --> R1["Consumers"]
C1 -->|"mirrored copy"| C2["Standby cluster"]
C2 -.->|"only after failover"| R2["Consumers"]
What must be copied
- Topic data. The messages themselves.
- Topic settings. Number of partitions, retention rules, and so on, so the standby behaves like the primary.
- Consumer positions. Where each consumer group stopped reading. Without this, applications restart at the wrong place, either re-reading everything or skipping data.
- Access rules and schemas. Permissions and message format definitions, if you use them.
It is a fire drill plus a backup office. Copies of all your important papers are kept in a second building, updated every few minutes. If the first office burns, staff walk to the second and continue. But they also need to know which paper they were reading, which is the same as copying consumer positions.
Strengths
- Simple to understand
- No conflicting writes, since only one side is active
- Standby can be smaller and cheaper
- Protects against whole-site loss
Limits
- The standby is idle most of the time
- Some data may be lost, depending on copy delay
- Failover needs practice or it will fail when needed
- Failing back is harder than failing over
Use Case Two: Serving Users From a Nearby Copy
Sometimes the goal is not survival but speed.
The problem
A company has one central cluster in one region, but readers of the data are spread across the world. A dashboard in Singapore reading from a cluster in Frankfurt suffers from the long round trip. Every read of a batch waits for the distance, and network costs for crossing oceans add up.
The solution
Mirror the needed topics into a cluster close to the readers. Local consumers then read from the local copy, at local speed. Writes may still happen in the central location. Only the read traffic moves close to the audience.
flowchart LR
W["Writers"] --> H["Central cluster"]
H -->|"mirror"| E["Europe copy"]
H -->|"mirror"| A["Asia copy"]
E --> RE["European readers"]
A --> RA["Asian readers"]
A publisher prints a magazine in one city, but ships copies to local warehouses. Readers buy from the nearest warehouse, not from the print shop across the world. The content is the same, but delivery is quick.
A hidden money saver
Cloud providers usually charge for data leaving a region. If ten applications in Asia each read the same topic from a cluster in Europe, the data crosses the ocean ten times. With a local copy, it crosses once, for the mirror, and the other nine reads stay local. For popular topics, this can cut the bill noticeably.
Copy only the topics the remote readers truly need. Mirroring everything wastes bandwidth and storage, and increases the amount of data you must secure.
Use Case Three: Collecting Data From Many Sites
Many small sources, one big picture: the aggregation, or hub-and-spoke, pattern.
The problem
A retail chain has hundreds of shops. Each shop runs a small Kafka cluster near its cash registers, so it can keep selling even when the internet is down. But headquarters wants one combined view: total sales, stock levels, and fraud patterns across every shop.
The solution
Each shop cluster mirrors its topics upward into a central aggregate cluster. Analytics jobs at headquarters read from the aggregate cluster only, and never need to talk to hundreds of separate sites.
flowchart TB
S1["Shop cluster 1"] --> AG["Aggregate cluster at headquarters"]
S2["Shop cluster 2"] --> AG
S3["Shop cluster 3"] --> AG
S4["Shop cluster N"] --> AG
AG --> AN["Analytics and reports"]
Why topic names matter here
If every shop calls its topic “sales”, the aggregate cluster would receive hundreds of streams with the same name. Mirroring tools often solve this by adding the source cluster’s name as a prefix, so “shop1.sales” and “shop2.sales” stay distinct. Analytics jobs can then read all of them together using a name pattern.
Each shop sends a daily report to headquarters. Headquarters stamps each with the shop’s name before filing them in one big cabinet. Without the stamp, reports from different shops would be mixed up.
Real-world picture: a restaurant group
A restaurant group runs small clusters in each city. Local clusters keep taking orders during network problems. Every few seconds, order events flow to the central cluster, where the finance team studies daily totals across all cities. If a city loses its internet for an hour, its data simply catches up when the link returns.
Use Case Four: Active-Active Operation
Both sites work, both sites serve users, and each site has the other’s data.
The problem
Some businesses cannot tolerate a cold standby. Users in two regions expect fast local service all the time, and a failure in one region should barely be noticed. An idle standby also feels wasteful when it could be doing real work.
The solution
Run two clusters, both active. Local applications write to their local cluster. Mirroring runs in both directions, so each cluster ends up with its own data plus a copy of the other’s. Each application can read a combined view.
flowchart LR
subgraph US["Region US"]
UP["US producers"] --> UC["US cluster"]
UC --> UR["US consumers"]
end
subgraph EU["Region EU"]
EP["EU producers"] --> EC["EU cluster"]
EC --> ER["EU consumers"]
end
UC -->|"mirror"| EC
EC -->|"mirror"| UC
The two big risks
- Loops. If cluster A copies a topic to B, and B copies it back to A, messages could bounce forever. Tools prevent this with naming rules, such as prefixing mirrored topics with the source name and never mirroring an already-prefixed topic back.
- Conflicts. If the same record, such as one customer’s address, is changed in both regions at once, the two versions collide. Kafka does not decide who wins. Your application design must handle it, for example by giving each region ownership of different records.
Two shops share one paper price list, and each shopkeeper phones the other whenever the list changes. If both change the same price at the same moment, they must agree on a rule for who wins. Otherwise customers see different prices depending on the shop.
Active-active is powerful but demanding. Choose it only when you truly need local writes in several regions, and design data ownership before writing the first line of application code.
Use Case Five: Data Location Laws and Compliance
Sometimes the reason for replication is not technology at all. It is a law or a contract.
The problem
Many regions have rules about personal data. Some say that data about their citizens must be stored inside their borders. Others say that a company must keep a second copy of certain records, perhaps for financial audits, in a separate location. A single global cluster cannot follow both kinds of rule easily.
The solution
Run one cluster per legal region. Raw, sensitive data stays in its home cluster. Only what is allowed to leave is mirrored elsewhere. Often that means copying selected topics, or copying topics that have been cleaned first, with names, addresses, and other personal fields removed or scrambled.
flowchart LR
subgraph R1["Region one, strict rules"]
RAW["Raw personal data topic"] --> CLEAN["Cleaning step"]
end
CLEAN -->|"only safe data leaves"| GLOBAL["Global analytics cluster"]
RAW -. "never copied" .-> X["Blocked"]
A hospital keeps patient files in its own building. It may send the health ministry a report of totals with no names in it. The report travels, the files never do. Topic filtering and cleaning in Kafka play the same role.
Practical rules
- Mirror by allow-list. Name the topics that may be copied, instead of copying everything except a few.
- Clean before copying, using a stream processing step that writes a separate, safe topic.
- Record who approved each mirrored topic. Auditors like to see the reasoning.
- Check the rules with legal experts. This guide explains the technique, not the law.
A backup copy is still a copy. If a rule says data must not leave a country, a disaster recovery cluster in another country may break it. Pick the backup location with the rule in mind.
Use Case Six: Cloud Migration and Hybrid Cloud
Move to the cloud without stopping the business, or live in both worlds on purpose.
Migration
A company has Kafka in its own datacenter and wants to move to a cloud provider. Switching in one night is risky, because dozens of applications depend on the cluster. A gentler path is to create a new cluster in the cloud, mirror all data from the old cluster into it, and then move applications over a few at a time. When the last application has moved, the old cluster is switched off.
Build the new cluster
Create the cloud cluster with matching topics and settings.
Start mirroring
Copy data and consumer positions from old to new. Wait until the copy is fully caught up.
Move consumers first
Readers switch to the new cluster, continuing from their translated positions.
Move producers next
Writers switch over. The old cluster stops receiving new data.
Retire the old cluster
After a safe waiting period, shut it down.
Hybrid cloud
Some companies never finish moving, on purpose. Old systems that touch factory machines or stores stay on premises, while new analytics and machine learning live in the cloud. Mirroring keeps a steady stream of events flowing between the two worlds, so each side sees what the other produces.
flowchart LR
subgraph ON["On premises"]
OC["Local cluster"] --> LEG["Legacy systems"]
end
subgraph CL["Public cloud"]
CC["Cloud cluster"] --> ML["Analytics and machine learning"]
end
OC -->|"events up"| CC
CC -->|"results down"| OC
Moving house without closing the kitchen. You buy the new house, carry things over room by room, and keep cooking in the old kitchen until the new one is ready. Mirroring is the moving van that runs back and forth until nothing is left behind.
Use Case Seven: Safe Upgrades and Big Changes
A second cluster is also a safe playground for risky changes.
Upgrading Kafka in place is usually safe, but large changes carry risk: a new major version, a new storage layout, a different number of partitions, or a move to a new hardware type. A trusted approach is called blue-green. The current cluster is “blue”. A new cluster, “green”, is built with the desired changes. Mirroring copies data into green. Applications move across gradually. If something goes wrong, they move back to blue, which is still healthy.
A restaurant opens a second kitchen with new equipment, cooks the same menu in both for a week, and only closes the old kitchen once the new one has proven itself. If the new stove misbehaves, the old one is still there.
Change partition counts
Partitions cannot be reduced in place, so a new cluster with new counts is a clean way out.
Major version jump
Test real traffic on the new version before committing.
New hardware or storage
Move from old disks to faster ones with a rollback path.
Reorganize topics
Clean up naming and settings without disturbing live users.
The same mirroring setup you use for disaster recovery can often serve as your migration path too. Practicing one prepares you for the other.
Use Case Eight: Sharing Data Across Teams and Companies
A separate cluster is a clean boundary. Mirroring lets data cross it on purpose.
Between business units
Large companies often let each team run its own cluster, so one team’s mistakes do not disturb another’s. But teams still need some shared events, such as “customer created” or “order paid”. Mirroring selected topics from one cluster to another shares exactly those events, and nothing more. The receiving team reads a local copy and cannot harm the sender’s cluster, even by accident.
Between companies
A retailer may want to share stock levels with its suppliers. A logistics company may want to share delivery updates with its clients. Giving outsiders direct access to your internal cluster is risky. Instead, you publish the shared topics to a dedicated exchange cluster and let partners read only from there.
flowchart LR
INT["Internal cluster"] -->|"approved topics only"| EXC["Exchange cluster"]
EXC --> P1["Partner one"]
EXC --> P2["Partner two"]
A company does not give suppliers keys to the warehouse. It builds a loading dock at the edge of the property. Goods are placed on the dock, and suppliers collect from there. The exchange cluster is that dock.
Strengths
- Internal cluster stays private
- Partners cannot overload internal systems
- Clear list of what is shared
- Each side manages its own security
Limits
- An extra cluster to run and pay for
- Small extra delay for shared data
- Schemas must be agreed and versioned carefully
- Removing shared data later is hard
Use Case Nine: Edge Sites and Unreliable Links
Some places have poor internet, yet still need Kafka’s reliability.
Factories, ships, mines, wind farms, stores, and vehicles all create data in places where the network can be slow or can disappear. A small Kafka cluster on the spot keeps local systems running regardless of the link. Whenever the connection is working, mirroring pushes the data to a central cluster. When the link breaks, data waits in the local topics. When it returns, mirroring resumes from where it stopped and catches up.
A mail box at a remote farm. Letters pile up while the road is flooded. Once the road reopens, the mail carrier collects them all in order. Nothing is lost, only delayed.
What this needs
- Enough local storage. The edge cluster must keep data long enough to survive the longest expected outage.
- Patient copying. The mirror tool must retry quietly and not give up.
- Ordered catch-up. After a long gap, data arrives in a rush. The central cluster must handle the burst.
Real-world picture: a shipping vessel
A cargo ship records engine readings every second into a tiny cluster on board. At sea, the satellite link is slow and expensive, so only summaries are mirrored. In port, the fast link opens and the full readings are copied to headquarters, where engineers study them.
The Tools That Do the Copying: MirrorMaker 2
The open-source answer that ships with Apache Kafka.
What it is
MirrorMaker 2 is the mirroring tool included with Apache Kafka. It is built on top of Kafka Connect, the framework for moving data in and out of Kafka. Instead of being one program, it is a small set of connectors that run inside Connect workers. Each connector has a different job.
| Part | Job | Everyday picture |
|---|---|---|
| Source connector | Copies topic data and topic settings from source to target | The courier |
| Checkpoint connector | Records where each consumer group is, translated for the target cluster | The bookmark copier |
| Heartbeat connector | Sends a small regular message to prove the link is alive | The pulse check |
Why it is popular
- Included and free. It comes with Apache Kafka.
- Many-to-many. One setup can mirror between several clusters at once.
- Topic and setting sync. New topics and changed settings can follow automatically.
- Consumer position translation. Explained in the next chapters.
- Loop protection. Mirrored topics get a prefix, so active-active does not bounce messages forever.
Points to keep in mind
- Mirrored topics have different offsets from the originals, so positions must be translated.
- Default naming adds the source cluster’s name in front of the topic name, which applications must understand.
- It is asynchronous, so the target is always slightly behind.
- You run and monitor the Connect workers yourself.
Older Kafka setups used the first-generation MirrorMaker, which was simpler but lacked settings sync and position translation. If you meet it in an old system, treat it as a candidate for replacement.
Other Tools: Managed Linking and Commercial Options
MirrorMaker 2 is not the only path. Know the other families so you can compare.
Byte-for-byte linking
Some platforms offer a built-in feature that links two clusters directly. The Confluent platform calls it Cluster Linking. Instead of a separate consumer-and-producer program, the target cluster pulls data from the source at a low level and stores an identical copy, with the same offsets. Because positions match exactly, consumer groups can move over without complicated translation. The catch is that such features depend on the vendor’s platform, and they may have their own version and licensing rules.
Connector-based commercial replicators
Vendors also sell replication connectors with extra features, such as easier setup, richer monitoring, and support contracts. They work much like MirrorMaker 2, using the Connect framework, but add polish and help.
Cloud provider features
Managed Kafka services from cloud providers often include their own replication tools, which run as a service so you do not operate workers yourself. Their capabilities differ between providers and change over time, so check current documentation before choosing.
| Family | Offsets preserved? | You run the copier? | Best for |
|---|---|---|---|
| MirrorMaker 2 | No, translated | Yes | Open-source, flexible, many topologies |
| Byte-for-byte cluster linking | Yes | No, built into the platform | Simple failover within one vendor’s ecosystem |
| Commercial connector replicators | Usually translated | Yes, with vendor support | Teams wanting support and easier tooling |
| Cloud provider replication services | Varies | Provider runs it | Teams already committed to one cloud |
Product features, names, and limits change often. Confirm current details in official documentation before you commit to a tool.
Another Option: The Stretched Cluster
One cluster, several sites, and no copier at all. Sounds perfect, but it comes with strict conditions.
How it works
In a stretched cluster, the brokers of one Kafka cluster are placed in several datacenters, usually three. Kafka’s normal internal replication then keeps copies of each partition in different sites. The brokers know which site they belong to through a setting called rack awareness, and Kafka spreads replicas across sites.
Why people like it
- No data loss on site failure, because a message is confirmed only after replicas in several sites have it.
- Automatic failover. Leaders move on their own, and offsets are identical since it is one cluster.
- Nothing to translate. Consumers see one system.
Why it is hard
- The sites must be close and the network fast. Every safe write waits for replicas in other sites, so a slow link makes every write slow.
- Three sites are needed to keep a majority when one fails, because the cluster’s coordination system works on voting.
- A broken link between sites can freeze writes rather than lose data.
- It suits nearby sites, such as availability zones in one region, and not far-apart continents.
flowchart LR
subgraph ONE["One stretched cluster"]
S1["Site A: brokers"]
S2["Site B: brokers"]
S3["Site C: brokers"]
end
S1 |"fast link"| S2
S2 |"fast link"| S3
S1 |"fast link"| S3
Three clerks in three offices must all sign every document before it counts. That works if the offices are in the same city and phones are clear. If the offices are on different continents and the phone line is poor, every document takes ages to approve.
How Mirroring Works Inside
A look under the bonnet, using plain words.
Step by step
Discover
The tool asks the source cluster which topics exist and picks those that match your allow-list.
Prepare the target
It creates matching topics in the target, with the same partition count and similar settings, under the mirrored name.
Read
Workers consume messages from each source partition, exactly like an ordinary consumer.
Write
They produce those messages into the same-numbered partition of the mirrored topic in the target cluster.
Note the mapping
The tool records how a source offset maps to a target offset, in a small internal topic.
Copy positions
The checkpoint part reads consumer group positions in the source, translates them with the recorded mapping, and stores the result for the target.
sequenceDiagram
participant S as Source cluster
participant M as Mirror workers
participant T as Target cluster
M->>S: Read new messages
S-->>M: Messages with source offsets
M->>T: Write to mirrored topic
T-->>M: Confirm with target offsets
M->>T: Store offset mapping
M->>S: Read consumer group positions
M->>T: Store translated positions
Why the same partition number matters
Kafka guarantees order only within one partition. By writing source partition three into target partition three, the mirror keeps the order of messages that belong together, such as all events for one customer. Changing the partition count would break that promise, which is why tools keep it identical.
A courier moves numbered envelopes from one office to another. The receiving office numbers them in its own way, so the courier also keeps a small notebook: “your envelope 500 is our envelope 512”. That notebook is the offset mapping.
The Hard Part: Consumer Positions During Failover
Copying messages is the easy half. Knowing where to resume reading is the tricky half.
The problem
A consumer group remembers how far it has read by storing an offset for every partition. After a failover, the group must continue on the standby cluster. But the standby’s offsets are usually different from the primary’s, because the mirror wrote its own copy. If the group starts with its old offset numbers, it could jump ahead and skip messages, or jump back and process old ones again.
You are reading a paperback and remember you stopped at page 200. Someone gives you a different edition, where the same chapter starts on page 215. If you open it at page 200, you re-read pages. If they hand you an edition where the chapter is on page 185, you skip pages. You need a table that says “page 200 in the old edition is page 215 in the new one”.
Three ways teams handle it
Translate offsets
Use the recorded mapping to compute the matching position in the target. Some tools even write it into the target’s consumer group automatically.
Use identical offsets
With byte-for-byte linking or a stretched cluster, offsets are the same, so no translation is needed.
Reset by time
Restart consumers from a timestamp shortly before the failure. Simple, but may cause repeats.
flowchart TB
F["Primary cluster fails"] --> Q{"How do consumers resume?"}
Q -->|"Translated offsets"| T["Resume near the exact spot, few repeats"]
Q -->|"Identical offsets"| I["Resume at the exact spot"]
Q -->|"Reset by timestamp"| R["Resume a bit earlier, expect repeats"]
Why translated positions are slightly behind
Position mapping is recorded periodically, not for every message. So the translated position is usually a little earlier than the true one. The result is that after failover, a consumer may re-read a small number of messages. That is safe, as long as your processing can handle seeing a message twice.
Assume after every failover that some messages will be seen again. Make consumers idempotent, meaning that handling the same message twice has the same effect as handling it once.
Naming, Loops, and Topic Layout
Names are how the tools stay sane when many clusters copy each other.
The prefix habit
By default, MirrorMaker 2 renames a mirrored topic by adding the source cluster’s alias in front. A topic called “orders” in the cluster nicknamed “east” becomes “east.orders” in the target. This has two big benefits. First, the target can hold its own “orders” topic and the mirrored one side by side without mixing them. Second, the tool can recognize a prefixed name and refuse to mirror it back, which stops loops.
flowchart LR
A1["east: orders"] -->|"mirrored"| B2["west: east.orders"]
B1["west: orders"] -->|"mirrored"| A2["east: west.orders"]
B2 -. "not sent back" .-> X["Loop stopped"]
What this means for applications
- A consumer that wants “all orders from everywhere” reads both “orders” and “east.orders”, or uses a name pattern that matches both.
- A consumer that wants only local orders reads the unprefixed topic.
- After a failover, applications must be able to read the prefixed topic name if the data they want now lives under a different name. Plan this in advance, or your failover will surprise you.
Keeping names identical
Some teams dislike prefixes and want the same names on both sides. Tools allow a custom naming rule that keeps names unchanged. This is convenient for active-passive, but dangerous for active-active, because without prefixes the loop protection disappears. Use identical names only when data flows one way.
Two offices forward letters to each other. If every forwarded letter gets a stamp “already forwarded from East”, the other office knows not to send it back. Remove the stamp, and letters may circle forever.
Ordering, Duplicates, and Exactly Once
What promises can a mirrored copy really keep?
Order
Order inside a partition is preserved, because the mirror copies partition to partition. But order between partitions was never promised by Kafka, and order between two clusters certainly is not. In active-active, events from two regions arrive interleaved in unpredictable ways.
Duplicates
If the mirror tool crashes just after writing a batch but before recording its progress, it will write the batch again after restart. Most mirroring setups therefore give at-least-once delivery: nothing is lost, but a few messages may appear twice. Newer versions of the tooling can offer stronger guarantees in some configurations, but verify carefully before relying on them.
Handling it in applications
- Idempotent consumers. Design processing so repeats are harmless.
- Unique message keys or ids. Let consumers recognize and skip messages they have already handled.
- Timestamps for tie-breaking. In active-active, timestamps or version numbers can decide which update wins, if clocks are reasonably in sync.
| Promise | Inside one cluster | Across mirrored clusters |
|---|---|---|
| Order within a partition | Yes | Yes, when partitions are copied one to one |
| Order across partitions | No | No |
| Zero loss on site failure | Only if replicas are in other sites | Not guaranteed, because of copy delay |
| No duplicates | Possible with care | Expect a few after failures |
| Same offsets | Yes | No, unless byte-for-byte linking is used |
A courier who is not sure whether the last parcel was signed for will deliver it again to be safe. The receiver may end up with two identical parcels. The polite fix is for the receiver to check the label and put the extra one aside.
Choosing the Right Design for Your Use Case
A guide from problem to solution.
| Your main goal | Best-fit shape | Key concern |
|---|---|---|
| Survive the loss of a site | Active-passive mirroring, or stretched cluster if sites are close | Copy delay and failover practice |
| Serve far-away users quickly | Read-only local copies | Cost of copying, freshness of data |
| Combine data from many places | Hub and spoke into an aggregate cluster | Topic naming and volume |
| Local writes in several regions | Active-active | Conflicts and loops |
| Keep data inside borders | One cluster per region with filtered mirroring | What may cross |
| Move to the cloud | Temporary mirroring old to new | Order of moving consumers and producers |
| Risky upgrade | Blue-green with mirroring | Rollback plan |
| Share with partners | Exchange cluster | Security and schemas |
| Unreliable sites | Edge clusters mirroring upward | Local storage and catch-up bursts |
flowchart TB
START["What is your main need?"] --> Q1{"Survive site loss with zero data loss?"}
Q1 -->|"Yes, sites close together"| SC["Stretched cluster"]
Q1 -->|"Small loss is acceptable"| Q2{"Do both sites need to write?"}
Q2 -->|"No"| AP["Active-passive mirroring"]
Q2 -->|"Yes"| AA["Active-active mirroring"]
START --> Q3{"Many sources, one view?"}
Q3 -->|"Yes"| HS["Hub and spoke"]
Advantages, Disadvantages, and Trade-offs
Everything useful here has a price.
Advantages of replicating across datacenters
- Survive a whole-site failure
- Faster reads for far-away users
- Lower cross-region data charges for popular topics
- Legal separation of data by region
- Gentle migrations and upgrades
- Clean boundaries between teams and companies
Disadvantages
- More clusters to run, patch, and pay for
- Copy delay means possible loss on disaster
- Offsets differ, making failover harder
- Duplicates and conflicts need application care
- Network costs between regions
- Failover procedures need constant practice
The main trade-offs
- Safety versus speed. Waiting for another site before confirming a write is safest but slowest. Copying afterwards is fast but may lose the last moments.
- Simplicity versus flexibility. Active-passive is easy to reason about. Active-active gives more but demands careful design.
- Cost versus readiness. A warm, full-size standby costs more but recovers faster than a small, cold one.
- Freshness versus bandwidth. Copying everything continuously keeps the target fresh, and uses the most network.
Insurance for a house. More cover gives more peace of mind and costs more every month. You choose a level that matches how much a loss would hurt, not the maximum on offer.
Security Across Sites
When data crosses a distance, protect it on the road and at both ends.
Protect the road
Traffic between datacenters travels over networks you may not control. Always use encryption in transit, so that anyone tapping the line sees only scrambled bytes. Where possible, use private links or dedicated circuits rather than the open internet.
Prove who is calling
The mirror tool logs in to both clusters. Give it its own identity, using certificates or strong credentials, and never share a person’s account. That identity should be allowed to read only the topics to be mirrored on the source, and to write only the mirrored topics on the target.
Match permissions on both sides
Access rules on the source do not automatically exist on the target. Someone who could not read a topic in the primary might be able to read its copy in the standby if you forget to copy permissions. Some tools can synchronize access rules, and some cannot, so plan this step explicitly.
Protect data at rest
The copy stores the same sensitive information. Encrypt disks, limit who can log in to the machines, and apply the same retention and deletion policies. When a user asks for their data to be deleted, remember that copies exist in more than one place.
The weakest cluster defines your security. A carefully guarded primary and a loosely guarded standby mean an attacker will simply visit the standby.
Sending valuables between two banks needs an armored van, a trusted driver, and equal security at both vaults. Locking one vault and leaving the other open defeats the purpose.
Monitoring, Logging, and Metrics
A backup you do not watch is a backup you cannot trust.
The key numbers
Replication lag
How far behind the target is. It is your live estimate of potential data loss.
Time behind
How many seconds old the newest copied message is. Easier for business people to grasp.
Throughput
Messages and bytes per second moving through the mirror.
Heartbeat age
Time since the last heartbeat arrived. A stale heartbeat means the link or the tool is stuck.
Worker and task status
Are all mirror tasks running, or did some fail?
Topic and partition parity
Do the target topics still have the same partitions and settings as the source?
What to log
- Every task restart, with the reason.
- Topics newly discovered or removed from the allow-list.
- Failovers and failbacks, with who did them and when.
- Authentication failures against either cluster.
What to alert on
- Replication lag above your RPO for longer than a set time.
- A stale heartbeat.
- Any failed or missing mirror task.
- A sudden drop of throughput to zero, which often means silence rather than health.
Monitor the monitor from a third location. If the alerting system lives inside the datacenter that just failed, no alert will ever be sent.
Capacity, Bandwidth, and Cost
Copying is not free, so size it like any other important system.
Bandwidth
The link between sites must carry the average flow of mirrored data, plus room for bursts and for catching up after an outage. If the link can carry exactly the average, a one-hour outage will never be recovered, because there is no spare room to run faster than new data arrives. Aim for a healthy margin.
Catch-up time
Catch-up time depends on the size of the backlog and the spare capacity. A simple way to think: if the backlog is ten hours of data and your spare capacity equals the normal flow, catching up takes about ten hours. If spare capacity is triple the normal flow, roughly five hours. Estimate this in advance so that your RPO promises are honest.
Storage
The target stores a full copy of every mirrored topic for as long as its retention rules say. Two clusters roughly double storage. Reduce cost by mirroring only needed topics and by giving the standby suitable retention.
Network charges
Cloud providers usually charge for data moving between regions, and sometimes between zones. Compress mirrored data, mirror only what is needed, and let consumers read the local copy rather than the far one.
Beyond Topics: Schemas, Settings, and Rules
A message is useless if the other side cannot understand it.
Schemas
Many teams describe the shape of their messages in a schema registry. If the standby has no copy of those schemas, its consumers cannot decode the messages after failover. Registries can be replicated, or synchronized by tools, so that the same schema identifiers mean the same thing in both places. Test this specifically, because it is a popular cause of failed failovers.
Topic settings
Retention, compaction, and message size limits should match on both sides. If the standby keeps data for a shorter time, some history will vanish sooner than expected. If it accepts smaller messages, large messages will fail to copy.
Access rules and quotas
Permissions and rate limits should be recreated on the target. Otherwise, after failover, either nobody can read, or everybody can.
Connectors and stream jobs
Applications that run inside the cluster world, such as connectors to databases and stream processing jobs, also need a plan. Will they run in both sites, or start in the standby only on failover? Their own internal state topics must be available too.
| Item | Copied automatically? | Action needed |
|---|---|---|
| Topic messages | Yes, by the mirror | Choose which topics |
| Topic settings | Usually, by the mirror | Check for drift |
| Consumer positions | If configured | Test translation |
| Schemas | Not by default | Set up registry replication |
| Access rules | Depends on the tool | Sync or recreate |
| Connectors and jobs | No | Plan and test start-up on standby |
Practicing Failover Before You Need It
The best plan on paper fails if nobody has tried it.
Why drills matter
Real disasters happen at bad times, with tired people and missing information. A plan that has been rehearsed becomes a habit. A plan that has never been tried is a guess. Practice reveals the small surprises: a forgotten permission, a hard-coded server name, an application that caches addresses forever.
Announce and agree
Choose a time, an owner, and a stop signal for the drill.
Freeze the primary
Stop producers, or pretend the primary is gone.
Switch clients
Point applications to the standby, using translated positions.
Check results
Measure loss, repeats, and time taken. Compare with your RPO and RTO.
Fail back and learn
Return to normal and write down every surprise.
A school fire drill. Nobody enjoys it, but on the real day children walk calmly to the exit because they have done it many times.
Make application configuration switchable by a single setting, such as a cluster alias, so a failover is one change and not fifty.
Deploying and Operating the Mirror
Where the copier lives, and how to keep it healthy.
Where should it run?
A common recommendation is to run the mirroring workers close to the target cluster. The idea is that the long-distance leg is the read from the source, and the write into the target stays local and reliable. If the long link breaks, a reader can simply retry, while a producer trying to write across a bad link risks awkward states. Different teams weigh this differently, so test in your own network.
Keeping it running
- Run several workers so one machine failure does not stop copying.
- Automate restarts with your platform’s health checks.
- Roll out changes gently and watch lag while you do.
- Keep versions aligned between Connect workers and clusters, following the compatibility notes.
- Track configuration in version control so changes are reviewed.
flowchart LR
SRC["Source cluster, far away"] -->|"long link, read"| W["Mirror workers near the target"]
W -->|"local write"| TGT["Target cluster"]
Design Patterns and Anti-Patterns
Habits worth copying, and habits worth avoiding.
Patterns that work
Allow-list mirroring
Name what is copied. Anything not named stays home.
Region-owned data
Each record has one home region that alone may change it, which avoids conflicts.
Local write, global read
Applications write locally and read a combined view of local and mirrored topics.
Cluster alias switch
Applications pick their cluster through one setting, making failover a single change.
Heartbeat watching
A regular tiny message proves the whole path works end to end.
Idempotent consumers
Repeated messages cause no harm.
Anti-patterns to avoid
What people do
They set up a standby cluster and never test a failover.
Why it hurts
Hidden problems such as missing permissions, schemas, or hard-coded addresses appear only during the real disaster.
Better approach
Schedule regular drills and record time, loss, and surprises.
What people do
They run active-active with both sides updating the same records, and hope for the best.
Why it hurts
Conflicting updates silently overwrite each other, and customers see inconsistent data.
Better approach
Give each record a home region, or define clear merge rules before going live.
What people do
They mirror every topic just in case.
Why it hurts
Bandwidth, storage, and security exposure grow, and sensitive data may cross borders by accident.
Better approach
Mirror by allow-list, based on a stated need for each topic.
What people do
They copy messages but forget schemas, permissions, and consumer positions.
Why it hurts
After failover, data exists but nobody can decode it, read it, or resume from the right place.
Better approach
Treat the whole system as the thing to replicate, not only the messages.
What people do
They stretch a cluster across distant continents.
Why it hurts
Every safe write waits for a slow long-distance round trip, so the whole system slows down.
Better approach
Stretch only across close, fast sites. Use mirroring for long distances.
Best Practices and Common Mistakes
A short checklist from many teams’ experience.
Best practices
- Write down RPO and RTO as numbers first
- Choose the simplest shape that meets them
- Mirror only what is needed
- Encrypt the link and secure both clusters equally
- Monitor lag, heartbeat, and task status
- Alert from a location outside the primary site
- Practice failover and failback regularly
- Make consumers idempotent
Common mistakes
- Assuming the standby is always up to date
- Ignoring the offset difference between clusters
- Forgetting schemas and access rules
- Running out of link capacity during catch-up
- Letting topic settings drift apart
- Never planning failback
- Keeping the monitor inside the failing site
- Choosing active-active for prestige, not need
About failback
Many teams plan the jump to the standby and forget the return. After the original site recovers, it is missing everything that happened during the outage. To return safely, you must copy the new data back, check that it is caught up, and only then move users back. Often it is wiser to make the former standby the new primary and rebuild the old site as the new standby, and avoid a second disruption.
After a temporary move to a friend’s house, you do not simply walk back into your repaired home with your old belongings. First you bring back all the new things you acquired, check that everything works, and then switch back.
A Failover Walkthrough
A made-up but realistic story, told slowly.
The situation
An online store runs its order events through a primary Kafka cluster in one city. A standby cluster in a distant city receives a mirrored copy of the order topics, the consumer positions, and the schemas. Their targets are to lose at most one minute of data and to be back within thirty minutes.
Normal evening
Replication lag hovers around a few seconds. The heartbeat is fresh. Everything is green.
The power fails
The primary site loses power and its backup generators fail. Orders cannot be written.
Alert from a third place
Because monitoring lives elsewhere, the on-call engineer is paged within a minute.
Decision
The engineer checks the last known lag, about five seconds, well inside the one-minute promise, and declares a failover.
Switch
The cluster alias setting is changed. Applications restart against the standby, with translated positions, and start reading the mirrored topics.
Cleanup
A few orders appear twice, and idempotent consumers ignore the repeats. About five seconds of orders are found missing and are reconstructed from payment records.
Recovery and review
Days later, the old site returns. It is rebuilt as the new standby. The team writes down what they learned.
sequenceDiagram
participant U as Users
participant P as Primary site
participant M as Mirror
participant S as Standby site
U->>P: Orders as usual
P->>M: Events flow
M->>S: Mirrored copy
Note over P: Power failure
U-xP: Orders fail
Note over S: Failover declared
U->>S: Orders continue
The story shows all the ideas together: an agreed RPO and RTO, a mirrored copy with monitored lag, translated consumer positions, idempotent processing, and a monitor outside the failing site. Each was a decision made long before the emergency.
Myths and Misunderstandings
Common beliefs that lead teams astray.
“Kafka replication already protects us from a datacenter loss.”
Only if replicas live in several sites. Replicas in one room share one fate.
“The standby has exactly the same offsets.”
Usually not. Mirroring writes its own copy with its own positions.
“Active-active means twice the safety with no extra work.”
It brings conflicts, loops, and naming rules that need careful design.
“Failover is automatic.”
Often it is a decision and a procedure. Automation must be built and tested.
“A backup we never open is a working backup.”
Only drills prove that it works.
“More topics mirrored means safer.”
It means more cost and more exposure, and not always more safety.
Real-World Patterns
How different kinds of companies typically use these ideas. The examples are generic pictures, not descriptions of particular firms.
Banking: safe and slow to change
A bank keeps its main and standby clusters in different cities, sets very tight lag alerts, drills failover several times a year, and mirrors a carefully approved list of topics. Its stretched cluster spans three nearby buildings for the most critical payment flows.
Streaming media: many regions, local speed
A video service runs clusters in several regions. Viewing events are written locally, then mirrored into a central analytics cluster. Recommendation systems read local copies for speed.
Manufacturing: edge and hub
Each factory has a small cluster that keeps working when the internet drops. Summaries flow up to a central cluster, where engineers watch machine health across the world.
Global software company: data residency
A software provider runs one cluster per legal region. Raw personal data never leaves its home region, and a cleaned, anonymous stream flows to a global analytics cluster.
Enterprise modernization: move and retire
A large enterprise mirrors its old on-premises cluster into a cloud cluster, moves applications over months, and finally switches off the old datacenter.
The Life of a Message Across Two Sites
Follow one order event from the moment it is created until it can be read in a faraway cluster.
The journey
Consider a single message: “Order 1001 was paid”. A producer application in the primary site sends it to the primary cluster. The leader of the right partition stores it, and followers in the same site copy it. Only then is the producer told that the write succeeded. At this point the message is safe inside one datacenter, but it exists nowhere else.
Next, the mirror workers, which are always asking the source cluster for anything new, receive the message. They write it into the matching partition of the mirrored topic in the target cluster, where the target’s own leader and followers store it. From that moment the message lives in two sites.
Finally, a consumer in the target site, perhaps a reporting application or a standby order processor, reads it. If the primary site is healthy, this reader is just an ordinary consumer of a local copy. If the primary is gone, the same reader becomes the survivor that continues the business.
flowchart LR
PR["Producer"] --> L1["Primary leader"]
L1 --> FL["Primary followers"]
L1 --> MW["Mirror workers"]
MW --> L2["Target leader"]
L2 --> FT["Target followers"]
L2 --> CO["Target consumers"]
Where the delay hides
- Waiting for the mirror to notice. Workers poll in small cycles, so a message may wait briefly.
- Crossing the distance. Physical distance sets a lower limit that no tool can beat.
- Batching. Tools group messages into batches for efficiency, which adds a little wait in return for higher throughput.
- Target write confirmation. The target cluster also replicates internally before confirming.
Add these together, and the total delay is your replication lag. In a healthy setup it is often a matter of seconds. In an unhealthy setup, such as after a link outage, it can grow to minutes or hours.
A letter written in one city has three stages: first the writer files a carbon copy in the local cabinet, then a courier collects letters from the outbox on a schedule, then the courier drops them at the other office, where they are filed again. The letter is only truly safe in both places after the last stage.
The lifecycle in a table
| Stage | Where the message lives | What a site loss would mean |
|---|---|---|
| Just written | Primary cluster only | Message lost if the primary site is destroyed |
| Picked up by the mirror | Primary cluster and in flight | Message may be lost, depending on timing |
| Stored in target | Both clusters | Safe from a single-site loss |
| Expired by retention | Removed from a cluster according to its rules | Gone from that cluster by design |
Applications That Read Mirrored Data
Copies only help when applications know how to use them.
Three ways to read
Local only
Read just the local topic. Simple, but blind to what other regions do.
Local plus mirrored
Read local and prefixed topics together, for a global picture.
Mirrored only
Read a copy of a remote source, as in an aggregate cluster or a standby after failover.
Stream processing and mirrored topics
Applications that combine and count events, such as stream processing jobs, keep their own state. That state usually lives in internal topics of the cluster where the job runs. After a failover, a job started on the standby needs either a mirrored copy of its state topics, or the ability to rebuild state by re-reading its input. Rebuilding may take a long time for big jobs, which affects your recovery time. Decide in advance which approach each job will use.
Connectors
Connectors that move data between Kafka and databases also track their progress in internal topics. If a connector runs in both sites at once, it may load the same rows twice. If it runs only in the primary, it must be started in the standby after a failover, with its progress data available. Write the answer down for each connector, as part of the failover checklist.
flowchart TB
subgraph PRI["Primary site"]
J1["Stream job"] --> S1["State topics"]
end
subgraph STB["Standby site"]
J2["Stream job, stopped"] -.-> S2["Mirrored state topics"]
end
S1 -->|"mirror"| S2
An accountant who keeps a running total in a notebook. If the office burns, a replacement accountant needs the notebook, or must re-add every receipt from the start of the year. The notebook is the state, and the receipts are the input topics.
Include every application, connector, and job in your failover inventory. The ones people forget are usually small tools that “just run in the corner”.
A Worked Example With Simple Numbers
Numbers make the trade-offs easy to see.
The setting
A company writes about twenty megabytes of order data per second into its primary cluster during the busiest hour, and about five megabytes per second at a quiet time. The standby is in a distant region. The company wants to lose no more than one minute of data and to recover within thirty minutes.
Bandwidth question
During the busiest hour the link must carry at least twenty megabytes per second. But the link also needs room to catch up. If the mirror is stuck for ten minutes at the peak, a backlog of about twelve thousand megabytes forms, since twenty megabytes per second for six hundred seconds is twelve thousand. If the link can carry forty megabytes per second, spare capacity is twenty per second, so the backlog clears in six hundred seconds, or another ten minutes. With only twenty-five per second, spare capacity is five, and the backlog would take forty minutes to clear, far longer than the outage. This is why headroom matters.
RPO question
While the mirror is stuck, the exposure grows. After a minute of backlog, the company has already reached its promised maximum loss. So the alert must fire well before one minute, perhaps at fifteen or twenty seconds of sustained lag, to leave time for humans and automation to react.
RTO question
Thirty minutes must cover detection, decision, switching applications, and warming up. If detection takes two minutes, the decision five, switching ten, and warming up ten, the total is twenty-seven minutes, which leaves almost no slack. The team might invest in automating the switch to bring it down to two minutes, and gain a comfortable margin.
| Step | Manual plan | After automation |
|---|---|---|
| Detect | 2 minutes | 1 minute |
| Decide | 5 minutes | 2 minutes |
| Switch applications | 10 minutes | 2 minutes |
| Warm up and verify | 10 minutes | 8 minutes |
| Total | 27 minutes | 13 minutes |
flowchart LR
D["Detect"] --> C["Decide"]
C --> S["Switch"]
S --> W["Warm up and verify"]
W --> OK["Users served again"]
Think of a motorway with a queue after an accident. If the road can carry only as many cars as usually arrive, the queue never disappears. Only a road with spare lanes clears it. Spare capacity is what turns a delay into a memory.
A Planning Checklist Before You Start
Questions to answer, in order, before building anything.
Name the goal
Which use case is it: recovery, local reads, aggregation, active-active, compliance, migration, upgrade, sharing, or edge? Pick the main one, and write it in a sentence.
Set numbers
Write RPO and RTO in minutes, and agree on them with the business owners.
List what matters
Which topics, applications, connectors, and jobs are essential? Which are not?
Check the rules
Are there legal limits on where data may go? Ask early.
Choose the shape and the tool
Use the decision guide and compare tools on offsets, operations, and cost.
Size the link and storage
Include headroom for catch-up, and estimate the network bill.
Design security
Encryption, identities, permissions, and equal protection on both sides.
Build monitoring
Lag, heartbeat, status, and alerts from an outside location.
Write the runbook and drill it
Failover, failback, and who decides. Practice until it feels boring.
If you cannot answer step 2 with real numbers, stop and get them before building. Everything else depends on those two numbers.
Before building a house you decide how many people will live in it, what budget you have, and what the local rules allow. Only then does the architect draw plans. Multi-datacenter Kafka is the same: the requirements shape the building.
Signs you may be over-building
- Nobody can explain which business promise the second cluster protects.
- Active-active was chosen but no region actually needs local writes.
- Every topic is mirrored, and nobody knows why.
- The team spends more time running the mirror than the applications it protects.
When you see these signs, step back and simplify. A modest active-passive pair that is well monitored and regularly drilled protects a business better than a grand design nobody fully understands.
Questions to ask before choosing a tool or vendor
- Are offsets preserved, or must consumer positions be translated, and how well is that translation tested?
- Who operates the copier, your team or the provider, and what happens when it fails at night?
- How are schemas, permissions, and topic settings synchronized, if at all?
- What monitoring is included, and can it alert you on lag and heartbeat?
- What are the limits, such as maximum throughput, number of topics, and supported versions?
- What does it cost, including the network charges between the sites?
- Can we leave later? Tools that lock you in should earn their place with real benefits.
Write the answers in a small comparison table and share it with the people who will be on call. The person who is paged at three in the morning should have a say in the choice.
Frequently Asked Questions
Summary and Key Takeaways
Everything in one place.
Cross-datacenter replication answers three basic worries: what if a site is lost, what if readers are far away, and what if rules say where data must live. From these worries come the use cases: disaster recovery, local reads, aggregation, active-active operation, compliance, migration, safe upgrades, partner sharing, and edge sites. Each maps to a shape: active-passive, active-active, hub and spoke, or a stretched cluster. The tools that do the copying, from MirrorMaker 2 to platform linking features, differ mainly in whether they preserve offsets and who runs them. Under all of them lie the same hard problems: copy delay, consumer positions, loops, conflicts, duplicates, schemas, security, and practice.
Key Takeaways
- Start from RPO and RTO. How much data you can lose and how long you can be down decides the design.
- Inside a cluster Kafka copies for you. Between clusters you must arrange it, with MirrorMaker 2, cluster linking, or a stretched cluster for nearby sites.
- Match the shape to the use case: active-passive for recovery, read copies for speed, hub and spoke for aggregation, active-active only when local writes truly matter.
- Offsets differ across mirrored clusters. Plan position translation, and make consumers idempotent to tolerate repeats.
- Replicate the whole system, including schemas, settings, and access rules, and not just messages.
- Secure and monitor both sides equally, watching lag and heartbeat from a place outside the primary site.
- Practice failover and failback. A backup that has never been tested is only a hope.