LESSON 05 · Multi-leader

Accept writes in more than one place

Several leaders give local writes and regional independence, in exchange for conflicts discovered after the fact.

SYSTEM VIEW

The replication path

Diagram view
Told yes—
Ben waits—

Watch two regions each take bookings locally and sell the last hotel room twice, then replay it with one home region that sells it once.

  1. A single leader sits in Region A, in Virginia; Region B in Sydney only copies. Ben’s write from Sydney crosses the world and back, a round trip of about 200 ms on every write, and if Virginia goes dark, writes stop.

    Sydney to Virginia
    about 200 ms
    Virginia goes dark
    writes stop

    What changed

    • Ben’s write goes to Virginia
    • 200 ms round trip
  2. Replay it with a leader in each region: each takes its own region’s writes and forwards them to the other asynchronously. The hotel has one room left. Region A sells it to Ana and confirms in 50 ms, without asking Region B.

    Each region
    takes local writes
    Forwarding
    asynchronous
    Ana to Region A
    50 ms round trip

    What changed

    • Region B leads too
    • Region A sells the room to Ana
    • Ana told yes
  3. Half a second later, Ben books the room in Region B. Ana’s booking hasn’t arrived there yet, so Region B sees the room free, sells it and confirms in 50 ms, with no trip to Virginia. Both guests have been told yes.

    Ben books
    500 ms after Ana
    Region B has
    no booking yet

    What changed

    • Region B sells the room to Ben
    • Ben told yes
    • One room, two guests
  4. Asynchronous replication runs behind, here 575 ms: Ana’s booking reaches Region B at 600 ms and Ben’s reaches Region A at 1,100 ms. Each region now holds two bookings for one room, and both guests were already told yes, too late to reject either.

    Replication lag
    575 ms
    Ana’s reaches B
    600 ms
    Ben’s reaches A
    1,100 ms

    What changed

    • Ana’s booking reaches Region B
    • Ben’s booking reaches Region A
    • A conflict in each
  5. Last-write-wins keeps the higher timestamp, Ben’s, in both regions and silently drops Ana’s; clock skew can make it drop the newer one. CRDTs merge counters and sets, or both versions wait for the app or a user to choose. All act after both guests heard yes.

    Last-write-wins
    drops a write
    CRDTs
    merge counters, sets
    Keep both
    app or user picks

    What changed

    • Both regions keep Ben’s booking
    • Ana’s booking, silently
  6. Replay it with a home region: Region A takes every write for this room, so Ben’s booking travels there and Region A, which sold it to Ana, answers sold out. The conflict never happens. Ben pays the 200 ms round trip; only a single owner can enforce “sell this room once”.

    Room’s home
    Region A
    Ben pays
    200 ms round trip
    Moving the home
    reopens the risk

    What changed

    • Region A owns the room
    • Ben’s booking refused
    • One guest told yes

Space plays · ← → step · Home resets

THE IDEA

How it works

A single leader forces every write to one location. A user in Sydney writing to a leader in Virginia pays a round trip of around 200 ms, and if that region goes dark, writes stop. In multi-leader replication, each region has a leader that accepts local writes and forwards them to the others asynchronously. Writes stay fast and a region can keep working alone. Offline apps are the same shape with far longer lag: each device is effectively a leader that syncs on reconnecting, as in a calendar or a CouchDB-based app.

The price is conflicts that appear after success has been reported. Say a hotel has one room left. Region A books it for Ana, and region B books it for Ben half a second later, before A’s write arrives. Each region commits and confirms. The conflict surfaces only when replication delivers the other write, too late to reject either.

The best response is to avoid conflicts by giving each record a home region that takes all its writes, though moving a record’s home reopens the risk. Last-write-wins keeps the highest timestamp and silently drops the other write, and clock skew can make it drop the newer one. Automatic merging uses conflict-free replicated data types (CRDTs), which combine concurrent changes to structures such as counters and sets. Or keep both versions and let the application or user choose.

Only a home region can enforce “sell this room once”, because that rule needs a single owner to decide. The others act after both sides have been told yes.

DECISION POINT

You run ticket sales from regions in Europe and the US. A product manager wants all writes local in both regions to keep checkout fast. The writes are user profile edits and seat purchases. How do you split them?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Multi-leader gives local writes and regional independence in exchange for conflicts found after the fact.
  • Giving each record a home region to avoid conflicts beats resolving them later.
  • Last-write-wins keeps replicas equal by throwing a write away.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
ApplyQUESTION 01

Two field technicians edit the same job note while offline, and the app resolves conflicts with last-write-wins. Both devices then sync. What is the result?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.