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.
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?
Treat them differently. Profile edits fit local writes: conflicts are rare and cheap, and a home region per user or last-write-wins per field is enough. Seat purchases should go to one owning region per event, because a double sale cannot be merged away. Distant buyers pay the extra round trip at the moment of purchase, and you tell the product manager that this one step stays slower on purpose.
Use this as a guide for self review; written answers are not graded.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.