Designing Global Multi-Datacenter Routing & Failover
A system design interview guide to sending every user to the right region, keeping data safe across regions, and surviving the total loss of a datacenter with little or no data loss and a fast recovery.
Student edition · start with the guarantee
Recover from a lost or isolated region without promoting a stale or unauthorized writer.
Correctness contract: Promotion follows a safe ownership/log protocol; the old writer is fenced at the actual resource. RPO/RTO are targets evaluated under explicit fault and routing assumptions.
Basic HTTP, databases, and programming are assumed. Specialized terms are explained below. Named products motivate the problem; this is an educational design, not a claim about their current internals. Capacity numbers are illustrative decimal payload estimates, not benchmarks. Add indexes, protocol overhead, replicas, headroom, and failure capacity before provisioning.
A service that runs in one datacenter is one power failure, fiber cut, or regional outage away from being down for everyone. Running in several regions fixes that, but it trades one hard problem for two: you must route each user to a healthy nearby region, and you must replicate state between regions so that losing one does not lose data. These two problems pull against each other through the laws of physics — the speed of light makes cross-region coordination slow, and the CAP and PACELC tradeoffs mean you cannot have strong consistency, low latency, and full availability at once. This guide works through both halves: the routing layer (GeoDNS, anycast, and GSLB), the choice between active-active and active-passive, synchronous versus asynchronous replication and what each does to your recovery objectives, and finally how to fail an entire region over without splitting the brain or losing writes.
Each definition includes a concrete example and the condition under which the mechanism is useful. You can read this guide without opening another guide.
RPO and RTO
Recovery Point Objective is the target maximum lost-data window; Recovery Time Objective is the target maximum recovery interval. Measured lag and drill duration are observations used to test those targets, not the targets themselves.
Example. At a constant 5000 acknowledged writes/s, an async standby 2 seconds behind lacks about 10,000 writes. Detecting, fencing, promotion, catch-up, and rerouting contribute separately to recovery time.
Limit. RPO=0 holds only for acknowledged durable commits under a stated failure model and safe recovery. DNS TTL and health checks do not give a universal hard upper bound on RTO.
Failure domains and redundant capacity
A failure domain is a set of components vulnerable to one shared event: process, host, rack, zone, or region. Redundancy must separate domains and leave enough surviving capacity to carry peak demand.
Example. Five replicas placed 2/2/1 across three regions leave at least three after any one region fails. A 3/1/1 layout can lose its quorum with the largest region.
Limit. Independent-failure probability formulas are illustrative assumptions. Shared code/config, dependencies, routing, and control planes can fail all replicas together. N+1 machines does not imply tolerance of a whole zone.
Quorum
A set of replicas whose responses are sufficient for an operation. In a fixed set of N replicas, read size R and write size W overlap whenever R+W>N. A majority is one particular quorum, not the definition of every quorum.
Example. With N=3, writes to {A,B} and reads from {B,C} share B. If the write completed durably and replicas preserve a comparable version, B carries that version forward.
Limit. Overlap alone does not provide linearizability: concurrent or failed writes, sloppy replica sets, and version selection matter. Consensus adds protocol rules to preserve decisions.
Fencing tokens
A strictly increasing grant number attached to operations. The protected resource atomically compares it with its durable highest accepted token and rejects older operations, making superseded clients unable to overwrite newer effects.
Example. A has token 33 and pauses. B acquires 34 and writes. When A sends token 33 later, the resource rejects it because its fence is already 34.
Limit. A new grant must be installed at the resource before it promises exclusion there. Token 33 can still pass until 34 is observed. Equal-token operations also need sequence/idempotency rules if they can arrive out of order.
Replication
Maintaining copies of data on independent storage nodes. Synchronous acknowledgement waits for specified durable copies; asynchronous replication sends changes after the client has already received success.
Example. A primary acknowledges after two durable copies in different zones. A follower that applies updates later can serve an old value even though the write is durable.
Limit. Replica count is not a complete durability or availability guarantee. State the failure domains, acknowledgement policy, promotion rules, repair process, and what happens if all copies fail.
CAP and consistency models
During a network partition, a distributed service cannot offer both linearizable operations and successful completion of every eligible request at nonfailed nodes. CAP consistency is linearizability; it is not durability or 'no bytes lost'.
Example. A minority that cannot contact the authority blocks or rejects a linearizable read/write. A mergeable append log can accept local writes on both sides and preserve both records, while not giving one-copy ordering.
Limit. Causal/session/eventual guarantees are not a universal availability ladder. Sticky routing alone fails after failover unless the new replica has satisfied the client's dependencies.
Intuition first
Think of two restaurants that share one recipe book. If the east kitchen burns down, diners must be sent west (routing), and the west kitchen must have the latest recipes (replication). Copying every recipe west before cooking is safe but slow. Copying later is fast, but the newest recipes may burn with the kitchen. Never let both kitchens rewrite the book at once.
1. Requirements & Scope
The requirements split cleanly into the two halves — getting users to a region, and keeping data correct across regions — plus the disaster case that ties them together.
Routing. Send each user to a healthy region, preferably the nearest, and stop sending traffic to a region that is failing or being drained.
Latency. Serve reads and writes close to the user; keep the extra cost of being multi-region off the common path.
Durability. Survive the complete loss of one region with a defined, small data-loss bound — ideally zero.
Availability. Stay up through a regional failure with a short, defined recovery time.
Correctness. Never let two regions both believe they are the writable primary — no split brain, no divergent histories.
Non-goals. This is not about scaling a single region (see the scaling guide); it assumes each region is already healthy on its own.
2. Back-of-the-Envelope
Two sets of numbers drive the design: the physics of cross-region latency, and the objectives that flow from the business.
Quantity
Assumption
Result
Cross-region round trip
US east–west ~3,000 mi = 4,828 km; fiber ~⅔ c ≈ 200,000 km/s gives a 24 ms one-way floor
~30–40 ms one way, ~60–80 ms RTT on real routes
Sync write penalty
every write waits one cross-region RTT
+~70 ms per write — on the hot path
Async replication lag
ship changes continuously
sub-second to seconds of exposure
DNS-based failover
record TTL 30–60s + resolver caching
minutes of stale routing worst case
Anycast reconvergence
BGP withdraws a failed POP
seconds to reroute
Target RPO / RTO
tier-1 service
RPO ~0 (sync) or seconds (async); RTO ~minutes
The single most important number is the cross-region RTT: ~70 ms. Every design choice below is really a decision about whether to pay that latency on the write path (synchronous, zero data loss) or to avoid it and accept a small data-loss window (asynchronous). Physics, not preference, forces the trade.
3. RPO, RTO & Key Definitions
The vocabulary of disaster recovery is precise, and interviewers expect it. Two numbers frame every failover design.
Term
Meaning
Driven by
RPO (Recovery Point Objective)
How much recent data you can afford to lose — the age of the last safe copy.
Replication mode (sync → 0, async → lag).
RTO (Recovery Time Objective)
How long you can be down — time to detect, promote, and reroute.
Failover automation and routing TTLs.
Active-active
All regions serve live traffic simultaneously.
Multi-master or partitioned ownership.
Active-passive
One region serves; others stand by, ready to promote.
Single primary + hot standbys.
Split brain
Two regions both act as writable primary and diverge.
A majority must agree before acting, so only one side can win.
Consensus (Raft / Paxos).
The mental model: RPO is a data question answered by replication, and RTO is a time question answered by automation and routing. Sync replication buys RPO = 0 at a latency cost; fast, well-drilled failover buys a low RTO.
4. High-Level Architecture
The shape is a global routing layer on top of two or more self-sufficient regions, with a replication channel between their data stores.
Users hit a global routing layer (GeoDNS, anycast, or GSLB) that steers them to the nearest healthy region. Each region runs a full stack — load balancer, stateless app tier, database — and the data stores replicate across regions, synchronously or asynchronously.
Global routing layer. Decides which region a user reaches, using health and proximity. It is the control point for failover — changing where traffic lands is how you evacuate a region.
Regional stacks. Each region is independently able to serve traffic: its own load balancer, its own stateless app tier (so any instance can serve any request), and its own copy of the data.
Replication channel. The data stores exchange changes across regions. The mode of this channel — synchronous or asynchronous — sets the RPO and the write latency.
Coordination. A consensus layer (or a managed equivalent) decides who is primary and prevents two regions from writing at once.
5. Routing: GeoDNS, Anycast, GSLB
There are three common ways to get a user to a region, and mature systems layer them. Each makes a different tradeoff between control, speed of failover, and connection stability.
GeoDNS. The DNS resolver returns a different IP based on the client’s approximate location, sending users to the nearest region. Simple and widely supported, but failover is only as fast as the record’s TTL plus resolver and OS caching — stale caches can keep sending users to a dead region for minutes after you change the record.
Anycast. The same IP address is announced from many locations via BGP; the network delivers each packet to the topologically nearest announcement. Failover is fast — withdraw the route and traffic reconverges in seconds — and it needs no DNS change. The classic caveat is that a mid-session BGP reconvergence can move a long-lived TCP connection to a different POP and break it, so anycast suits stateless, short-lived requests (DNS itself, CDN edges, UDP/QUIC) best.
GSLB (Global Server Load Balancing). A smarter DNS/load-balancing tier that answers with a region chosen from live health checks, capacity, and latency — not just geography. It actively steers away from unhealthy or overloaded regions and is the usual home for weighted failover and traffic-shaping policy.
In practice you combine them: anycast to reach the nearest edge/POP fast, GSLB (health-aware DNS) to choose the healthy origin region, and short DNS TTLs so a policy change propagates quickly. Whatever the mechanism, the routing layer must be driven by real health signals, because routing to a region that is failing is worse than routing nowhere.
6. Replication & Consistency
Synchronous means acknowledgement waits for the configured durable copies/commit rule; asynchronous means local commit can be acknowledged before remote catch-up. RPO=0 requires placement and promotion that preserve every acknowledged commit under the stated failure budget. A bare remote ACK or majority counter without protocol/placement is not sufficient.
Async lag is an observed gap, not automatically a fixed bound. Semi-sync implementations may have timeout fallback, so check actual modes. A consensus majority follows election/log rules, including Raft's current-term commit condition. Partitioned write ownership needs fenced ownership transfer; it does not sidestep failover conflicts merely by choosing one home region initially.
7. Failover & Split-Brain
Timeouts and monitor agreement establish suspicion, not proof a primary died. Obtain safe promotion authority through the storage/consensus protocol. Fence the old primary at the actual effect/resource boundary; a DNS change or cooperative lease revoke alone does not stop delayed writes.
Choose a candidate using committed history and recovery rules, not simply the largest observed log position. An uncommitted divergent suffix can be longer. Synchronous replication protects acknowledged commits only if the configured durable placement and failover protocol recover all of them under the fault model. A candidate can catch up from surviving quorum members; it need not itself have acknowledged every original commit.
Async failover may lose acknowledged data not available from survivors. Last observed primary position and sampled lag are incomplete evidence; distinguish bytes/log entries from seconds and expose uncertainty. Reroute with client/session handling, warm the survivor, verify critical read/write journeys, and resync the old region under a new epoch. Drills validate achieved recovery, not an absolute timing guarantee.
8. Worked Example: RTO and RPO Budgets
A sample staged budget of 30s detection+30s confirmation+10s fencing+30s promotion+60s DNS+60s client/resolver allowance totals 220s≈3.7 minutes. It is an illustrative budget, not a hard worst-case bound. Some stages overlap; some clients cache longer or retain old connections.
DNS-based GSLB still depends on resolver behavior; anycast also has route convergence and connection considerations. Measure detection, authority, catch-up, fencing, traffic convergence, and critical-operation recovery independently. Async missing-write count is approximately rate×lag only under steady rate and a trustworthy lag sample; outages/spikes can enlarge it. State RPO/RTO targets and measured drill results separately.
9. Failure Modes
Failure
Why it hurts
Defense
Gray failure (slow, not dead)
Health checks pass while users time out
Check real user paths and latency, not just "port open"
Flapping failover
Traffic bounces back and forth, each time risking data
Confirmation window, hysteresis, and a human gate for fail-back
Fencing fails
Old primary keeps writing: split brain
Don't promote until fencing is confirmed; storage rejects old epochs
Survivor region lacks capacity
New region falls over under double load
Plan N+1 capacity; shed low-priority traffic
Control plane lives in the dead region
You cannot run the failover
Run failover tooling and its config store in every region
Clients ignore DNS TTL
Some users stay on the dead region
Anycast, client-side retry to a second endpoint
10. Bottlenecks & Tradeoffs
The tensions here are fundamental — they come from the network and from CAP/PACELC, not from implementation.
Latency vs durability. Sync replication gives RPO 0 but taxes every write with a cross-region RTT; async gives fast writes but a nonzero data-loss window. This is the central trade and it cannot be optimized away, only placed.
Consistency vs availability. Under a partition you must choose: refuse writes to stay consistent (CP), or accept writes on both sides and reconcile later (AP). Pick per data type — money is CP, a like counter can be AP.
Failover speed vs safety. Aggressive automated failover lowers RTO but risks flapping and false failovers on a transient blip; conservative failover is safe but slow. Quorum detection plus a brief confirmation window balances the two.
Routing freshness vs caching. DNS caching helps performance but slows failover; anycast reroutes fast but can break long connections. Layering (anycast + short-TTL GSLB) mitigates both.
Cost. Active-active means paying for capacity in every region and cross-region bandwidth; active-passive is cheaper but wastes standby capacity and has a colder, slower failover. Choose by how much downtime and data loss actually cost the business.
11. Summary
Global multi-region design is two problems bound by the speed of light: route users to a healthy region, and replicate data so losing a region does not lose the data. Every choice is a placement of the same latency-versus-durability trade.
Concern
Mechanism
How do users reach a region?
GeoDNS for proximity, anycast for fast reroute, GSLB for health-aware steering — layered.
How much data can we lose?
RPO — set by replication: sync/quorum → 0, async → the lag window.
How long can we be down?
RTO — set by detection, automated promotion, and routing TTLs.
All regions live or standby?
Active-active for latency and utilization; active-passive for simplicity and lower cost.
How do we replicate correctly?
Sync/quorum for RPO 0 at a latency cost; async for speed; partition write ownership to avoid conflicts.
How do we avoid two primaries?
Quorum-based promotion plus fencing of the old primary — the cure for split brain.
How do we know it works?
Regular DR drills / game days that actually evacuate a region and measure RPO and RTO.
The recurring theme: you cannot beat physics, so you place its cost deliberately. Decide per data type whether zero data loss is worth a cross-region round trip, route on real health rather than geography alone, and make failover safe with quorum and fencing — then prove it in drills before the real outage proves it for you.
Worked example: async lag and a safe promotion
Assume 5000 acknowledged writes/s and a standby 2 seconds behind at failure.
Read top to bottom. The table below explains the state and guarantee at each step.
Step
State, calculation, and reasoning
1. Estimate missing writes
About 10,000 under constant rate/known lag. Bursts, unseen commits, and stale monitoring can make that estimate wrong; record uncertainty.
2. Obtain promotion authority
Monitors suspect unreachability; they cannot prove death. A consensus/ownership protocol and fencing govern promotion, not majority health votes alone.
3. Select and catch up a valid candidate
Use committed-log rules and available durable copies. The most advanced raw log position can include uncommitted divergent entries and is not automatically safe.
4. Reroute and measure recovery
DNS TTL, resolver caches, persistent connections, cache warmup, and client retries affect convergence. RTO is measured by successful critical operations, not just a DNS change.
Check your understanding: Does promoting any synchronously replicated node guarantee RPO=0?
Only if it durably contains or safely recovers every acknowledged commit under the configured replication/promotion protocol and failure budget. A label 'sync replica' alone is insufficient.
Run a small, testable model
Download concepts.py. It uses only the Python 3.10+ standard library. From the directory where you saved it, run:
python3 concepts.py quorum
python3 concepts.py test
The majority-placement model compares 3/1/1 with 2/2/1 and shows surviving quorum capacity.
The program contains deterministic assertions and failure traces. It is a learning model, not a production service: it does not implement network consensus, distributed durability, authentication, or third-party delivery. Read its contracts and try changing an input before extending it.
"How long is failover?" Break the RTO into steps and add them up. Point out that DNS dominates.
"How much data do you lose?" Writes per second times lag for async. Zero only from a sync replica.
"How do you avoid split brain?" Quorum decides, fencing enforces, epochs make old writes fail.
"Active-active or active-passive?" Home each key's writes in one region. Serve reads locally.
"How do you know it works?" Game days that really evacuate a region and measure both numbers.
13. Common Mistakes
Asking the dead primary how far ahead it was. It is dead. Use the last monitored position, and call the loss a lower bound.
Promoting any replica and claiming RPO 0. Only the sync replica has every acked write.
Forgetting DNS caching in the RTO. The TTL and resolver caching often take longer than the promotion itself.
Promoting before fencing is confirmed. That is how split brain happens.
Never testing fail-back. Returning to the old region needs a resync and is its own risky change.
14. Check Yourself
Detection 30 s, confirmation 30 s, fencing 10 s, promotion 30 s, DNS TTL 60 s, resolver slop 60 s. What is the RTO?
Answer
30 + 30 + 10 + 30 + 60 + 60 = 220 s, about 3.7 minutes. More than half of it is routing.
The primary takes 5,000 writes/s with 2 s of async lag. How many writes can a region loss destroy?
Answer
About 5,000 × 2 = 10,000 acknowledged writes. If lag spikes to 30 s, it becomes 150,000.
Why can't the failover script compute primary.log_pos - candidate.log_pos?
Answer
The primary is unreachable, so its position cannot be read. The script can only use the last position monitoring saw. Writes after that sample are unknown, so the result is a lower bound on the loss.
You have one sync replica in region B and one async replica in region C. Region A dies. Which do you promote, and why?
Answer
B. It acked every committed write before the client was told "done", so promoting it gives RPO 0. Promoting C would lose whatever C had not yet received.
Why fence the old primary if it is probably dead anyway?
Answer
"Probably dead" may mean partitioned or paused. If it comes back and writes, you get two primaries. Fencing (epochs, lease revocation, detached storage) makes its late writes fail, so a wrong guess is harmless.
Name two ways to cut the RTO above by about two minutes.
Answer
Replace DNS failover with anycast, or put a health-checked GSLB or L7 proxy in front that switches origins in seconds. Either removes most of the 120 s of TTL and resolver slop.
15. Key Terms
RPO
Maximum data loss you accept, as time or writes.
RTO
Maximum downtime you accept.
GeoDNS
DNS answers that depend on the client's location.
Anycast
One IP announced from many places; BGP picks the nearest.
GSLB
Health- and load-aware global traffic steering.
Fencing
A strictly increasing grant number attached to operations. The protected resource atomically compares it with its durable highest accepted token and rejects older operations, making superseded clients unable to overwrite newer effects. Example and limits above.
Gray failure
A node that is slow or partly broken but looks alive.
Game day
A planned drill that triggers a real failover.
16. Further Reading
Betsy Beyer et al., Site Reliability Engineering (O'Reilly, 2016), chapters on load balancing and managing critical state.
Martin Kleppmann, Designing Data-Intensive Applications, ch. 5 on leader failover and replication lag.
AWS Well-Architected Framework, Reliability Pillar, on disaster recovery strategies and RTO/RPO.
Peng Huang et al., "Gray Failure: The Achilles' Heel of Cloud-Scale Systems", HotOS 2017.
Corbett et al., "Spanner: Google's Globally-Distributed Database", OSDI 2012.