Multi-region design
Read first: Replication, Consensus and Raft, Consistency models
Active-passive keeps one writer and accepts a recovery time and a possible tail of lost writes. Active-active serves writes in more than one region and then has to reconcile conflicts. Do not recommend active-active as the default, and treat residency as a placement constraint rather than a latency feature.
A new-grad loop usually should not reach for multi-region writes, and it usually does not ask you to run them. One primary, a replica, and a failover you can describe will answer the question they grade. This page is still worth an evening, because the follow-up about a dead region is where people invent active-active and then cannot say what happens to one account written on both sides.
Core concepts
Active-passive. One region accepts writes. Another holds a replica and does not. Failover promotes the replica, and it takes time. That elapsed time is the RTO you have to operate: detect the failure, fence the old primary so it cannot keep accepting writes, promote the standby, and send clients there. Two primaries is split brain. Replication already told you why fencing exists. A lease or a generation number stops the old primary from taking writes after you have given the job to someone else. Clocks alone are a poor fence.
If replication is asynchronous, the standby is missing the tail. Those commits existed on the old primary and never shipped. When you promote, they are gone, or they are stuck on a disk you cannot reach. If replication is synchronous, the write does not return until the standby has it, so the tail is empty and the write now waits on the far region. A slow or dead standby stalls writers. Synchronous replication buys a smaller loss and spends availability and latency to do it.
Active-active. More than one region accepts writes for the same data. Each write can return after its local commit. The regions reconcile later, or they try to. During a partition, both sides can still answer, which is the availability you were shopping for, and both sides can accept a write the other has not seen. PACELC is the clean way to say this. If there is a partition, you trade availability against consistency. Else, even on a healthy link, you trade latency against consistency. Active-active with asynchronous replication is the latency side of the healthy trade: the user does not wait for the other region, and the other region is stale until the bytes arrive. Synchronous replication across regions is the consistency side: every write pays the fiber, and a sick far region becomes your availability problem. During a real partition you do not get both linearizability and a response from every live node. A system that keeps accepting writes on both sides of the cut has chosen availability and now owes a merge.
Eventual consistency, if the updates stop, means the replicas converge. It says nothing about what a reader sees before that, and nothing about which of two concurrent writes survives. You have to pick the rule on purpose. Leaving it as “the database will sort it out” is how the rule becomes whatever the last replica to speak happened to store.
RPO and RTO. RPO is how much data you can lose. Speak it as a duration and then turn it into rows, so it is not a slogan. An RPO of one second means you can afford to lose about one second of commits. RTO is how long you can be down, from the failure until users can be served again. They are independent. A design can lose nothing and take an hour to come back, or lose a minute of writes and come back in a few heartbeats, if you already have a warm standby and you accept the tail. Name both numbers before you name a topology. They are the requirements. Active-passive versus active-active is a way to hit them, not a personality.
Residency. Some rows are allowed to live in one place and not in another. That is a product and legal constraint on placement. It is not a latency feature, and it is not a reason to turn on a second writer. If an account must stay in the EU, the bytes are not written in a US region because a traveling user would see a shorter round trip. The traveling user pays the trip to the home region. A passive replica for that account has to sit somewhere the bytes are allowed to sit. Failing over an EU account into a US region breaks the constraint you were failover-ing to protect. Active-active across those two regions breaks it earlier, the first time the US region accepts the write.
Conflict resolution, before the second writer. Two writes to the same account, accepted in two regions, have to become one account. The options you can actually explain:
A single writer, which is active-passive or a home region per account. There is no conflict. The region that does not own the account refuses the write or forwards it. You pay RTO when the home region is down, or you pay the round trip to home on every write.
Last-writer-wins on the whole row. You need a total order. A timestamp plus a replica id can give you one. Clocks alone are a poor order. Clocks are a whole topic, and the useful sentence here is that a wall clock tie is not a merge policy. Whole-row last-writer-wins keeps one write and drops the other, even when the writes touched different fields.
Per-field last-writer-wins. Email and password can both survive if each was written as its own field and you merge fields. A client that read a stale profile and wrote the whole row back will still clobber the field it did not mean to change, because the write contained the old value and the rule believed it. The merge unit is the write you accepted, not the field you wish the client had sent.
A merge function with no central authority is a CRDT, and it costs metadata. A server that picks the order is a simpler system and is not a CRDT. Do not reach for the term because two regions exist.
None of these is free. The reason not to recommend active-active as the default is that a new-grad design almost always survives an RTO, and almost never has a merge rule the author can walk through on one account. Say active-passive. State the RPO and the RTO. Stop.
Spanner is the far end of the menu, not the opening bid. It gives external consistency: if one transaction commits before another starts, the first has the smaller timestamp, including across regions. TrueTime returns an interval that contains the true time. Commit wait holds the commit until that interval is past the chosen timestamp. Each group of replicas runs Paxos. A transaction that touches several groups uses two-phase commit on top of those leaders. The cost is commit wait, tied to clock uncertainty, and the operational cost of the clocks. The original paper treats the uncertainty as milliseconds, kept small with GPS and atomic clocks. Do not invent a single epsilon. A design that says “use Spanner” has not answered the question. A design that says “one region, one primary, and here is the failover” usually has. Read the Spanner story when you want the mechanism. Do not wear the name as a substitute for RPO and RTO.
flowchart LR
westUser[West coast user]
eastUser[Netherlands user]
west[West account row]
east[Netherlands account row]
westUser --> west
eastUser --> east
west --> east
east --> west
Both arrows between the rows are the active-active case: each region accepts a write and ships it later. Delete one direction of writes, leave the replica arrow, and you have active-passive. The diagram is the choice. It is not a recommendation to keep both writers.
A worked example
The resource is one account row: email, and a password hash. You are considering two regions, a west-coast region and a Netherlands region. Dean’s teaching number for a California-to-Netherlands round trip is about 150 ms. A shorter path you can derive: light in fiber is about 200 km per millisecond, so a 4,000 km path is about 20 ms one way and about 40 ms round trip before routers. Coast-to-coast planning sits in the tens of milliseconds. The 150 ms figure is the long path, oceans and routers included. Use it when the regions really are that far apart. Use the fiber floor when you are sketching a 4,000 km pair and do not yet have a measurement. Say which one you are using.
Assumptions for the rate:
- 1,000,000 account writes a day. A planning assumption, so the shortcut shows.
- Peak is 5 times the average. An assumption.
- Replication lag, when you replicate asynchronously and the link is healthy, is one second. An assumption, not a measured SLA. You would replace it with the lag you actually see.
- The conflict is not caused by the lag being large. It is caused by both regions accepting a write.
1 day = 86,400 seconds
shortcut ≈ 100,000 seconds
1,000,000 / 86,400 ≈ 11.6 writes/s
1,000,000 / 100,000 = 10 writes/s
peak, assume 5x ≈ 58 writes/s
synchronous replica, California to the Netherlands
each write pays about 150 ms
Little's law at the average:
11.6 * 0.150 s ≈ 1.7 writes in flight on the fiber
at the assumed peak:
58 * 0.150 s ≈ 8.7 writes in flight
async lag, assume 1 second
writes in the tail ≈ 11.6
that tail is the RPO, if the primary dies
Throughput is not the argument. Fewer than ten writes sitting on the ocean is nothing. The user-facing 150 ms on every synchronous write is the argument, and so is the stall: if the Netherlands replica stops answering, west-coast writes stop with it. You coupled availability across an ocean to avoid a conflict.
Now the conflict, which you only have if both regions accept writes. Call it active-active, asynchronous, same account, no home region.
At 10:00:00 the user changes their email in the west-coast region. The local commit succeeds. The Netherlands row still has the old email.
At 10:00:00.400 a password change commits in the Netherlands. Maybe the user is traveling. Maybe a retry landed on the other region. Maybe a support tool did. It read the old row and wrote a new password hash. Both commits are real. Neither region has seen the other write yet.
When the replicas meet, each side holds a version the other did not produce.
Whole-row last-writer-wins keeps one of the two rows. You lose either the new email or the new password, depending on which write the total order ranks later. The user sees a successful email change and a successful password change. One of them is gone. That is the bug, and it is worse because both responses were 200.
Per-field last-writer-wins can keep both, if the west write contained only the email and the Netherlands write contained only the password, and your merge is per field. If the Netherlands client read the profile, changed the password, and wrote the whole profile back, the write contains the old email. The merge will set the email back. You did not want a CRDT. You wanted to notice a stale read-modify-write. A conditional write, “update the password if the version is still the one I read,” would have rejected the Netherlands write once the email change landed, or rejected the email change if the password landed first. Someone then has to retry. That is a conflict policy too. It is the one a single-region database already gave you, and you do not get it across two writers unless you build it.
This is why the default is active-passive. The west-coast region is the primary. The Netherlands region is an async replica. The password change that arrived in the Netherlands is forwarded to the primary, or refused. There is one order, the primary’s order. The RPO, under the one-second lag you assumed, is about a dozen account writes if the primary dies before the tail ships. Say that number out loud and ask whether a dozen account updates is an acceptable loss. If it is not, shorten the lag or replicate synchronously and put the 150 ms on the write. The RTO is how long until the Netherlands region is promoted and clients go there. A DNS name with a long TTL cannot be your only plan: caches will keep the old answer for the TTL, and a low TTL fails over faster and increases lookup load. RTO is at least that TTL plus detection, fencing, and promotion. If you needed an RTO of a minute, a TTL of an hour and a human who has to wake up do not meet it. Pick the number, then make the mechanism fit. Do not pick active-active because the RTO felt awkward to say.
Residency changes the map and does not change the default. An EU account’s home is the EU region. The replica lives in a second EU site, not on the west coast of the US. A user sitting in California still sends the write to the EU home and pays the round trip, about 150 ms on this path. You do not open a west-coast writer to hide that number. The moment the west-coast region accepts the write, the bytes live outside the place you promised. Active-active was a latency optimization that broke a constraint. The honest sentence is the opposite: residency tells you where the single writer is, and the user who is far away waits.
What you tell the interviewer, even on this optional page: one region, one primary, async replica if a disaster copy is required, RPO equal to the unreplicated tail, RTO equal to the failover you have actually practiced, fencing so the old primary stays down. Active-active only if the product cannot live with that RTO and you can walk the email-and-password conflict without hand-waving. Almost no new-grad design is in that position.
Tradeoffs
| Choice | What you gain | What you spend |
|---|---|---|
| Active-passive, async replica | One writer, a simple order, a disaster copy | RPO is the unreplicated tail. In the example, about one second and a dozen writes, under an assumption |
| Active-passive, sync replica | A promoted standby is missing nothing | Every write waits on the far region, about 150 ms on the long path, and a dead standby stalls you |
| Active-active, async | A write can commit in more than one region | Conflicts on one account, and a merge rule you must already have |
| Home region per account | Residency holds, and there is still one writer | A user far from home pays the round trip. A dead home region is an RTO, not a local write |
| Last-writer-wins on the whole row | A deterministic survivor | The other field change is silently dropped |
| Naming Spanner and stopping | You pointed at external consistency | You skipped the choice, and you pay commit wait plus the clocks |
Consensus inside one region does not remove the fiber. Raft and Paxos make a replica group agree. They do not make a cross-ocean round trip cheap. Running a quorum across the 150 ms path means the commit waits on that path. That is the synchronous row of the table, whether the algorithm has a famous name or not.
Pitfalls
- Recommending active-active as the default so the design looks global. The symptom is two successful writes to one account and no sentence for which one survives.
- Quoting RPO and RTO as words you memorized, without turning them into lost rows and elapsed failover. The symptom is “RPO is low” while the replica is asynchronous and the lag is unmeasured.
- Synchronous replication across regions, then surprise that writes take 150 ms and stop when the far region does. The symptom is a local outage caused by a remote one.
- Failover without fencing. The symptom is split brain: the old primary still takes writes, and you now have the conflict you built active-passive to avoid.
- A US failover target for an EU-resident account. The symptom is a disaster plan that breaks the constraint the moment it runs, or an active-active write that breaks it sooner.
- Last-writer-wins on a stale read-modify-write of the whole profile. The symptom is an email change vanishing because a password form wrote the old email back.
- Treating residency as a reason to add regions. The symptom is more writers, not a legal placement. Residency removes writers. It does not add them.
- “Use Spanner” as the first sentence. The symptom is a design with no RPO, no RTO, and no idea what commit wait costs.
In the interview
This page is optional. In a new-grad loop, do not open with it. Open with one region and one primary. If they ask about a dead region, say active-passive. “Async replica, RPO is the replication lag, which I will measure and which I am assuming is about a second at this sketch, about a dozen writes at a million writes a day. RTO is detection plus fencing plus promotion plus DNS. I am not taking writes in both regions, because an email change and a password change would both return success and one of them would lose.” That is a path, a number, a bottleneck (the lag, or the 150 ms if they demand sync), and one honest tradeoff.
Skip multi-master conflict-free types unless they push. Skip the Spanner paper’s clock hardware unless they ask how anyone gets a single order across regions. If they do, commit wait and TrueTime are the answer, and the cost is milliseconds plus operational clocks, and it is still not the default.
The question that usually follows is the conflict, even if you refused active-active. They want to hear that you know what you avoided. Walk the two writes. Whole-row last-writer-wins drops a field. A stale full-row writeback drops a field even if you thought you merged per field. The single writer does not have the problem. Then they ask about residency. Home region, replica inside the allowed area, the traveling user waits. You do not open a writer next to the traveler.
Check yourself
In the account example, what are RPO and RTO if the primary dies under a one-second async lag?
RPO is the data you can lose: about one second of commits that never reached the standby. At roughly 12 writes per second that is about a dozen account updates, and both the one second and the rate were assumptions you have to say. RTO is how long users wait before the standby is promoted, fenced, and actually receiving them. A DNS TTL is only the lower bound on the client move. The two numbers are not the same number.
Why is active-active a poor default for a new-grad design?
Both regions can accept a write to the same account. An email change in one and a password change in the other both return success, and something has to drop or merge them. Whole-row last-writer-wins drops one. A stale full-row writeback clobbers a field you did not mean to touch. The product almost always survives a stated RTO with one writer. Recommend active-passive unless you can walk that conflict and the product truly cannot wait.
Synchronous replication from California to the Netherlands. What do you add to the write, and what is that number?
About 150 ms, Dean’s teaching round trip for that path, on every write, before routers you have not measured make it worse. A 4,000 km fiber floor is about 40 ms round trip if the regions are only that far apart. Say which geography you mean. The write also stalls if the far region stops answering. You bought an empty tail and paid latency plus coupled availability.
An EU account must stay in the EU. The user is in California. Why is a west-coast writer the wrong fix for the latency?
Residency is a constraint on where the bytes live, not a feature you get from a second writer. A west-coast commit puts the account outside the EU the moment it succeeds. The user sends the write to the EU home and pays the round trip, about 150 ms on the California-to-Netherlands path. The passive replica, if you need one, sits in another site where those bytes are allowed to sit. Failover into California breaks the same constraint.
Based on: PACELC, Daniel Abadi; Spanner, OSDI 2012, Corbett and others; Werner Vogels on eventual consistency; Jeff Dean, Numbers Everyone Should Know; Designing Data-Intensive Applications, Kleppmann and Riccomini.