Multi-Cluster Kafka: MirrorMaker 2, Disaster Recovery and Data Migration
Why More Than One Cluster?
- Disaster recovery: survive the loss of a whole region or data center
- Geo distribution: serve users and data close to them, aggregate regional data in a central cluster
- Migration: move to a new cluster, new cloud or managed service with little downtime
- Isolation: separate analytics or partner clusters from the core cluster
Not the same as replication inside a cluster: A single cluster stretched over far-apart regions suffers from high latency and complex failure modes. Prefer one cluster per region (or per site) and mirror data asynchronously between them.
MirrorMaker 2 (MM2)
MirrorMaker 2 is built on Kafka Connect and replicates topics, consumer group offsets and configuration between clusters. (The old MirrorMaker 1 was removed in Kafka 4.1, so use MM2.)
| Connector | Job |
|---|---|
MirrorSourceConnector | Copies records from source topics to the target cluster. Remote topics get the source cluster alias as a prefix: primary.orders |
MirrorCheckpointConnector | Translates consumer group offsets so consumers can resume in the other cluster |
MirrorHeartbeatConnector | Emits heartbeats to measure replication health and latency |
text
Region A (primary) Region B (DR)
topic: orders --- MM2 ---> topic: primary.orders (prefixed copy)
group: email-service --- checkpoints -> translated offsets for email-service
Dedicated MM2 Configuration
text
# connect-mirror-maker.properties
clusters = primary, backup
primary.bootstrap.servers = primary-broker1:9092,primary-broker2:9092
backup.bootstrap.servers = backup-broker1:9092,backup-broker2:9092
primary->backup.enabled = true
primary->backup.topics = shop\..*, payments\..* # regex of topics to mirror
primary->backup.groups = .*
primary->backup.topics.exclude = .*[\-\.]internal, .*\.replica, __.*
# replication settings in the target
replication.factor = 3
offset-syncs.topic.replication.factor = 3
checkpoints.topic.replication.factor = 3
heartbeats.topic.replication.factor = 3
sync.topic.configs.enabled = true
sync.topic.acls.enabled = false
emit.checkpoints.enabled = true
sync.group.offsets.enabled = true # write translated offsets to the target __consumer_offsets
refresh.topics.interval.seconds = 60
tasks.max = 8
bash
bin/connect-mirror-maker.sh config/connect-mirror-maker.properties # run 2 or more instances for high availability
Topologies
| Pattern | Description | Notes |
|---|---|---|
| Active-passive | Applications use the primary. DR cluster receives copies and stays idle | Simple. On failure switch applications to the DR cluster |
| Active-active | Both clusters serve applications, each mirrors to the other | Remote topics have different names (prefix) so there is no replication loop. Applications read both local and remote topic (orders and primary.orders). Conflict handling needed |
| Hub and spoke (aggregation) | Edge clusters mirror into a central cluster | Analytics and global views |
| Migration | Old cluster to new cluster, then cut over | Mirror, move consumers, then producers |
RPO and RTO
| Term | Meaning | With MM2 |
|---|---|---|
| RPO (recovery point objective) | Maximum acceptable data loss | Equal to replication lag: asynchronous, so the last seconds of data may not be copied when the primary fails |
| RTO (recovery time objective) | Time until service works again | Depends on your failover procedure and automation (DNS, config, application restart) |
Asynchronous means possible loss and duplicates: After failover the DR cluster may miss the newest events, and translated offsets are approximate, so consumers may reprocess some records. Idempotent consumers are essential.
Failover Procedure (Active-Passive)
- Confirm the primary is really unavailable and decide to fail over (avoid split brain)
- Stop or fence applications still writing to the primary if possible
- Check the DR cluster: mirrored topics are present, check mirror lag before the outage (heartbeats)
- Point producers to the DR cluster. Producers write to the topic names your design defines (often the original name in DR via a separate topic, or the prefixed topic)
- Start consumers on the DR cluster. Use translated offsets (
RemoteClusterUtils.translateOffsetsorsync.group.offsets.enabled), or reset to a timestamp slightly before the outage - Monitor lag and errors, communicate status
java
// translate offsets of a group from primary to backup (Kafka MirrorMaker client utility)
Map<TopicPartition, OffsetAndMetadata> translated =
RemoteClusterUtils.translateOffsets(backupProps, "primary", "email-service", Duration.ofSeconds(30));
// then consumer.assign(...) and consumer.seek(tp, translated.get(tp).offset()) on the backup cluster
Failback
- Do not simply point everything back. First resync the primary: mirror the data produced in DR back to the primary (reverse direction), or rebuild the primary from DR
- Plan a quiet window, drain traffic, switch producers and consumers in a controlled way
- Rehearse failover and failback regularly (game day). A DR plan that is never tested usually fails
Alternatives and Related Tools
| Option | Notes |
|---|---|
| Cluster linking (vendor feature) | Byte-for-byte topic mirroring with identical offsets in some commercial platforms, simplifies consumer failover |
| Stretched cluster across 3 zones in one region | Good for zone failure, not for region failure |
| Kafka Connect + object storage backups | Archive topics to S3 or GCS for long-term backup and replay |
| Stream replication by the cloud provider | Managed replicators in MSK, Event Hubs and others |
Monitoring Mirroring
- MM2 metrics:
replication-latency-ms,record-count,byte-rate,checkpoint-latency-ms - Heartbeat topic freshness between clusters
- Compare end offsets of source and mirrored topics for key topics
- Alert when mirror lag exceeds your RPO
Conclusion
MirrorMaker 2, built on Kafka Connect, copies topics, offsets and configs between clusters asynchronously. Choose active-passive for simple DR or active-active for geo needs, accept that RPO equals lag, make consumers idempotent, and rehearse failover and failback.
Quick Summary: MM2 = source + checkpoint + heartbeat; prefixed remote topics; RPO = lag; test failover/failback.

