← Back to System Design, page 5

system-design-0091 · Hard senior

How do you run a service active-active across several regions? Cover traffic routing, data replication, write conflicts and what happens when a region fails.

Every region serves reads and writes for nearby users, with traffic steered by latency-based DNS or anycast. Data replicates asynchronously between regions, so concurrent writes to the same item in two regions can conflict; avoid that by giving each record a home region, or resolve conflicts with CRDTs or last-write-wins where acceptable. When a region fails, routing moves its users elsewhere, accepting that writes not yet replicated may be lost or delayed. Strongly consistent global writes cost a cross-region round trip per write.

Full answer

Why active-active

Active-passive keeps a standby region idle until disaster; failover is slow, rarely tested and the standby may not handle full load. Active-active uses every region all the time, gives low latency to users everywhere and makes failover a routing change.

Routing

  • Latency-based or geo DNS sends each user to the nearest healthy region; TTLs of 30 to 60 seconds limit how long clients stick to a dead region.
  • Anycast (one IP announced from many places) with a global load balancer reacts faster, in seconds.
  • Sticky homes: route a signed-in user to their home region when possible, so their reads see their own writes.

Data replication options

  1. Home-region partitioning (most common). Each user, tenant or account has one home region that accepts its writes; other regions get asynchronous copies for reads. No write conflicts, because only one region writes each record. Moving a user's home is an explicit migration.
  2. Multi-leader with conflict resolution. Any region writes any record and replicates asynchronously. Concurrent updates conflict:
    • last-write-wins by timestamp (simple, silently loses updates);
    • CRDTs for counters, sets, carts (merge without loss);
    • application merge rules or showing conflicts to users.
  3. Globally consistent databases (Spanner, CockroachDB, YugabyteDB with global tables) use consensus across regions. Every write waits for a majority of regions, adding tens to hundreds of milliseconds, but there are no conflicts.

Many systems mix: global consistency for small critical data (usernames, payments), home-region writes for user data, CRDTs for counters.

Region failure

  • Routing removes the failed region within seconds to minutes.
  • With asynchronous replication, the last few seconds of writes in that region (the replication lag) may be missing elsewhere: the recovery point objective is the lag, not zero.
  • For home-region data, another region is promoted as the new home for affected users; when the old region returns, its unreplicated writes must be reconciled, not blindly applied.

Other concerns

  • Data residency laws may require some users' data to stay in a region, which limits replication.
  • Capacity: each region must absorb a failed region's traffic; with three regions, run each at under about 66% of peak.
  • Global services such as ID generation, auth keys and configuration must also be multi-region, or they become the hidden single point of failure.
  • Test failover regularly by draining a region on purpose.

By level

Fresher: Explain that several regions serve users at once and copy data to each other. A fresher should see that two regions editing the same thing at once can conflict.

Mid: Compare home-region partitioning, multi-leader with conflict resolution and global consensus. Describe failover with replication lag.

Senior: Discuss mixed strategies per data type, recovery point objectives, reconciliation after failback, residency, headroom and failover drills. Expect precise trade-offs.

Key points

  • Every region serves traffic; routing by latency DNS or anycast
  • Home-region ownership avoids write conflicts
  • Multi-leader needs LWW, CRDTs or app merges
  • Global consensus databases avoid conflicts at the cost of cross-region latency
  • Async replication means failover can lose the last few seconds of writes

Common mistakes

  • Assuming async replication gives zero data loss on failover
  • Using last-write-wins for money or inventory
  • Forgetting capacity headroom to absorb a failed region
  • Leaving global dependencies in a single region

Follow-ups

  • How would you migrate a user's home region?
  • How do you handle unique usernames across regions?
  • How would you test region failover safely?

Tips

  • Separate routing, data and failure handling
  • Present home-region ownership as the default
  • State the recovery point honestly

Evaluation rubric

  • Clear routing design
  • Correct replication options and conflicts
  • Realistic failure analysis
  • Capacity, residency and global dependency awareness