100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is a Master-Master Replication Topology?

Understand master-master (multi-master) database replication, why write conflicts occur, and how they get resolved.

hardQ85 of 228 in Database Est. time: 6 minsLast updated:
Open Code Lab

Expected Interview Answer

A master-master (multi-master) replication topology lets two or more servers each accept writes independently, and every master streams its changes to every other master so all copies eventually converge.

Because any node can write, applications can send traffic to the geographically or logically nearest master, improving write latency and removing a single write bottleneck. The hard part is that two masters can accept conflicting writes to the same row at nearly the same time, so the system needs a conflict-resolution strategy such as last-write-wins timestamps, version vectors, or application-level merge logic. This added complexity is why master-master is chosen deliberately for specific workloads, rather than as a default over simpler single-master setups.

  • Writes accepted at multiple locations, lowering write latency
  • No single point of failure for write availability
  • Useful for active-active geo-distributed deployments
  • Removes the single-master write bottleneck

AI Mentor Explanation

Imagine two international boards independently updating the same player's career statistics after simultaneous matches in different countries, each board syncing its update to the other afterward. If both boards recorded a century in the same over due to a scoring error, someone has to decide which entry wins, unlike a single official scorer who never contradicts themselves. Master-master replication faces exactly this: two writable copies can genuinely disagree and need a conflict-resolution rule to converge.

Step-by-Step Explanation

  1. Step 1

    Configure multiple writable masters

    Each node is set up to accept both reads and writes, not just replay changes.

  2. Step 2

    Stream changes bidirectionally

    Every master ships its change log to every other master, and vice versa.

  3. Step 3

    Detect conflicting writes

    The system flags cases where the same row was modified on two masters before syncing.

  4. Step 4

    Resolve conflicts deterministically

    Apply a rule such as last-write-wins by timestamp, version vectors, or app-level merge logic.

What Interviewer Expects

  • Recognition that multiple nodes accept writes, not just one
  • Explicit mention of write-write conflicts and how they are resolved
  • Awareness of the added operational complexity vs single-master
  • A concrete use case, e.g. geo-distributed active-active systems

Common Mistakes

  • Describing it as just replication with extra read replicas
  • Failing to mention conflict resolution at all
  • Assuming master-master eliminates all availability concerns
  • Confusing it with sharding, where each server owns different rows

Best Answer (HR Friendly)

โ€œMaster-master replication means more than one server can accept writes, and they sync changes with each other so every copy stays up to date. The tricky part is handling two servers writing to the same record at nearly the same time, which needs a clear rule for deciding which change wins.โ€

Code Example

Conceptual conflict-aware write pattern
-- Each master stores a last-modified timestamp per row
UPDATE Accounts
SET balance = balance - 100,
    updated_at = CURRENT_TIMESTAMP
WHERE account_id = 42;

-- During sync, if both masters changed account_id = 42,
-- the replication process keeps the row with the later
-- updated_at value (last-write-wins) and discards the older one,
-- or raises a conflict for manual/application-level resolution.

Follow-up Questions

  • How does last-write-wins conflict resolution actually work?
  • What is a version vector and how does it detect conflicts?
  • When would you choose master-master over master-slave?
  • How do you handle auto-increment ID collisions across masters?

MCQ Practice

1. What distinguishes master-master from master-slave replication?

In master-master, multiple nodes independently accept writes and sync with each other, unlike the single writer in master-slave.

2. What new problem does master-master replication introduce?

Since multiple nodes can write independently, the same row can be modified differently on two masters before syncing.

3. Which is a common conflict-resolution strategy in master-master setups?

Last-write-wins using timestamps (or version vectors) is a common deterministic way to resolve conflicting concurrent writes.

Flash Cards

What is master-master replication? โ€” Multiple nodes each accept writes and sync changes bidirectionally with each other.

Main benefit of master-master? โ€” Lower write latency and no single write bottleneck across locations.

Main challenge of master-master? โ€” Resolving write-write conflicts on the same row from different masters.

Common conflict resolution strategy? โ€” Last-write-wins by timestamp, or version vectors / app-level merge logic.

1 / 4

Continue Learning