Quick revision
The short answer
Run MirrorMaker 2 in both directions with the default replication policy, so east's orders appears in west as east.orders and west's in east as west.orders; MM2 never replicates a topic back to the cluster in its prefix, which prevents loops, and that is why IdentityReplicationPolicy cannot be used. Deploy each flow near its target, have consumers subscribe to the local and remote topics so each region processes the union, and accept that ordering holds only within one partition of one source topic. Avoid conflicts by giving each entity a home region that alone writes its events, and when a region fails, keep serving from the other while consumers stay idempotent and tolerant of late data.
What to remember
In this answer, we built active-active replication from two MM2 flows with the default replication policy, so each region holds its own orders and a prefixed copy of the other's, with loops prevented by the prefix. Each flow runs near its target, consumers subscribe to the local and remote topics and process the union, ordering holds only within a partition of one source topic, and conflicts are avoided with a home region per entity. When a region fails the other keeps serving, and idempotent consumers absorb late and repeated events.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Run MirrorMaker 2 in both directions with the default replication policy, so east's orders appears in west as east.orders and west's in east as west.orders; MM2 never replicates a topic back to the cluster in its prefix, which prevents loops, and that is why IdentityReplicationPolicy cannot be used. Deploy each flow near its target, have consumers subscribe to the local and remote topics so each region processes the union, and accept that ordering holds only within one partition of one source topic. Avoid conflicts by giving each entity a home region that alone writes its events, and when a region fails, keep serving from the other while consumers stay idempotent and tolerant of late data.
Why this question is asked
Active-active Kafka sounds like the best of both worlds: each region writes locally with low latency and sees everything. The cost is that two regions now produce events about the same business without a shared clock or a shared log. Interviewers ask this design to see whether we can make the plumbing correct, with naming, loop prevention and subscriptions, and also face the hard part honestly: ordering and conflicts. In this answer, we will lay out the topology and naming, decide where each flow runs, set up the consumers, work through ordering and conflicts, and plan for the loss of a region.
1The Topology and Topic Naming
Each region keeps writing its own orders to a local topic called orders. MM2 runs two flows: east->west copies east's orders into west, and west->east copies west's orders into east. With DefaultReplicationPolicy, a copied topic carries the alias of the cluster it came from, so west holds orders, written by west's order service, and east.orders, copied from east. East holds orders and west.orders.
- Order service in eastwrites east's orders locally
- east cluster: orders + west.orderslocal events plus west's copy
- MM2 flows near each targeteast->west and west->east
- west cluster: orders + east.orderslocal events plus east's copy
- Order service in westwrites west's orders locally
5 layers, from the top down. Step through them one at a time.
Loops are prevented by the names. The east->west flow could match west.orders in east, but the prefix says it came from west, and MM2 never sends a topic back to the cluster it came from. Each event therefore crosses the link once. With IdentityReplicationPolicy, both copies would be called orders, MM2 could not tell local from replicated data, and every event would bounce back and forth, so it cannot be used in this topology. Note that the topics setting here matches orders exactly, not a pattern that would also catch east.orders.
2Where Each Flow Runs
Each MM2 flow should run near its target cluster: the east->west workers run in west, consuming from east across the link and producing locally. Fetching across a long link copes with latency well, because a consumer can keep large fetches in flight, while producing across it suffers more, since producer acknowledgements must make the round trip and larger in-flight windows bring their own risks. Running near the target also keeps MM2's own state topics local. So we have two MM2 deployments, one per region, each responsible for bringing the other region's data home.
3How Consumers Subscribe
A consumer in west that must see all orders subscribes to both orders and east.orders. It then processes the union: west's events with almost no delay and east's events after replication lag, typically under a second within a continent but more during trouble.
Notice that aggregates must accept events from both sources. A daily revenue total in west must add west's orders and east's, and must not assume they arrive in the order they happened. The origin taken from the topic name is useful for metrics and for conflict rules.
4Ordering and Conflicts: the Hard Part
Kafka orders records only within one partition of one topic. Replication preserves that: east.orders in west has the same per-partition order as orders in east. But there is no order at all between an event written in east and one written in west. They are in different topics, and replication lag means a west consumer can see a later local event before an earlier east event. If both regions change the same customer's order within the lag window, each region sees its own change first, and they may disagree about the final state.
The cleanest way to avoid conflicts is to make them impossible: give each entity a home region. Customer 42 lives in east, so only east writes events about customer 42; a request that lands in west is forwarded to east or rejected. Every entity then has exactly one writer and one ordered history, and the other region just reads a slightly delayed copy. If the business truly needs both regions to write the same entity, consumers need explicit conflict rules, such as last writer wins by a timestamp, merges that commute, or domain rules like cancellation wins over update, and those rules must be designed and tested, not hoped for.
| Guarantee | Holds? | Notes |
|---|---|---|
| Order within one partition of one source topic | Yes | Kept by replication |
Order across orders and east.orders | No | Separated by replication lag |
| Same offsets in both clusters | No | Records are re-produced |
| No conflicting writes | Only with a home region | Otherwise explicit conflict rules |
5When a Region Fails
If east fails, west keeps taking orders and serving everything it has, including east.orders up to the last replicated event. Customers whose home is east are the open question: either west takes over as their home for the duration, which must be a deliberate, recorded switch to avoid two writers, or their writes wait. Events written in east but not yet replicated are not lost if east's disks survive; when east returns, MM2 resumes from its committed position and delivers them late.
So consumers must be idempotent, because MM2 may redeliver around the restart, and tolerant of late data, because an event from before the outage can arrive hours later. Aggregates and reports should be able to correct themselves when late events arrive, rather than assuming yesterday is closed.
6Follow-up questions
Why not write every order to both clusters from the order service?
Dual writes have no atomicity across regions: one write can succeed while the other fails, and the two clusters diverge in ways nobody notices. Writing locally and replicating with MM2 gives one source of truth per event and a single mechanism to monitor.
Should consumer offsets be synced between regions here?
Usually not. Each region's consumer groups process both topics locally and have their own positions. Syncing makes sense only for a group that would move from one region to the other on failover.
How do we measure replication lag between regions?
With MM2's replication-latency-ms and record-age-ms metrics, and with heartbeats: comparing a heartbeat's timestamp with when it arrives in the other region gives an end-to-end figure we can alert on.
7Conclusion
In this answer, we built active-active replication from two MM2 flows with the default replication policy, so each region holds its own orders and a prefixed copy of the other's, with loops prevented by the prefix. Each flow runs near its target, consumers subscribe to the local and remote topics and process the union, ordering holds only within a partition of one source topic, and conflicts are avoided with a home region per entity. When a region fails the other keeps serving, and idempotent consumers absorb late and repeated events.
Open with
I would run MirrorMaker 2 in both directions with the default replication policy. East's orders show up in west as east.orders and west's in east as west.orders. That prefix is what prevents loops, because MM2 never replicates a topic back to the cluster named in its prefix, so IdentityReplicationPolicy is out for this topology.
Then, if they want more
Each flow runs near its target cluster, so it consumes across the link and produces locally, which handles latency better. Consumers that need everything subscribe to both the local topic and the remote one, orders and east.orders, or a pattern, and aggregates have to accept events from both sources. The hard part is ordering.
Kafka only orders within one partition of one topic, so there is no order between an event written in east and one in west, and replication lag separates them. I would avoid conflicts by giving each entity, say each customer, a home region that alone writes its events; the other region forwards or rejects writes.
If the business insists on writes in both, consumers need explicit conflict rules that we design and test. When a region fails, the other keeps serving with the replicated copy.
Events not yet replicated arrive late when the region comes back and MM2 resumes, so consumers must be idempotent and tolerate late data, and any move of home regions during the outage must be a deliberate switch.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design the MirrorMaker 2 topology: topic naming, how consumers subscribe, how loops are...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-operations/dcc6fe0a6d/