Multi-region databases with read replicas, multi-leader, home regions and consensus: an interactive latency map
Serving users on three continents from one database means somebody pays an ocean round trip on every request. Moving data closer splits into a few designs: read replicas near users with one leader for writes, multi-leader replication where every region writes, a home region for each record, or consensus across regions as in Spanner and CockroachDB. Each moves the cost somewhere else: to write latency, stale reads, conflicts or what a region outage loses.
The playground places users 50% in the US, 30% in Europe and 20% in Asia, with real-world round trips between Virginia, Ireland and Singapore. Pick a design, switch between per-user data and a shared document, and take us-east down.
Reads are local everywhere, 1 ms, but every write crosses to the leader in Virginia: 75 ms from Europe and 220 ms from Asia. Replicas trail the leader, so a user in Asia who writes and then reads can miss their own write for up to 120 ms.
- Read
- 1 ms
- Write
- 1 ms
- Read
- 1 ms
- Write
- 75 ms
- Read
- 1 ms
- Write
- 220 ms
US to Asia: 220 ms round trip.
What each design costs
- One region is simple and consistent, but Europe waits 75 ms and Asia 220 ms on every request, and a region outage takes the whole product down.
- Leader plus read replicas makes reads local everywhere while writes still cross to Virginia. Replicas lag, so a user in Asia can miss their own write for up to 120 ms unless reads after a write go to the leader. Losing the leader loses the writes that had not replicated, about 48 ms of them, and stops writes for everyone until a replica is promoted.
- Multi-leader makes reads and writes local and survives a region loss without refusing writes. It is safe when each record is only written from one region; when the same record is written in several, concurrent writes conflict, here about 44 times an hour on one busy document, and need last-writer-wins, CRDTs or application merges.
- A home region per record gets local reads and writes for data owned by one user without conflicts, because each record still has a single leader. Shared records pay a cross-region write, and a region outage stops writes only to the records homed there.
- Consensus across regions never loses an acknowledged write and never conflicts, because a majority of regions commits every write. Each write waits for the nearest other region: 75 ms between the US and Europe, 160 ms from Asia.
Placing data by region
-- CockroachDB: each row lives, and is led, in its owner's region
ALTER DATABASE app SET PRIMARY REGION "us-east1";
ALTER DATABASE app ADD REGION "europe-west1";
ALTER DATABASE app ADD REGION "asia-southeast1";
ALTER TABLE users SET LOCALITY REGIONAL BY ROW; -- local reads and writes for the owner
ALTER TABLE currencies SET LOCALITY GLOBAL; -- rarely written, read fast everywhere
-- the same idea by hand: route each user to their home region's database
home = directory.lookup(user_id) # cached; written once at sign-up
db = pools[home]In a system design interview
When the requirements say global users or survive a region outage, split the data by who writes it: “User-owned data is homed in the user’s region, so their reads and writes stay local and there is one writer per record. Rarely changed reference data is replicated everywhere. Money and inventory, where a lost or conflicting write is unacceptable, use consensus across three regions and accept 75 to 160 ms writes. Reads that may be slightly stale come from local replicas.” Expect the follow-ups: what happens to in-flight writes when a region fails, how users who travel are handled, and how you route a request to the right region.
Read the guide to multi-region architecture or active-active vs active-passive, see the CAP theorem and database failover, or watch a strong candidate design a payment system.
Questions people ask
What is a multi-region database?
A database whose replicas run in several geographic regions, so that users far from the primary region get lower latency and the system survives the loss of a whole region. Designs differ in where writes are accepted and how replicas agree.
What is the difference between active-active and active-passive across regions?
Active-passive serves writes from one region and keeps others as replicas that take over on failure. Active-active accepts writes in every region, either with multi-leader replication, which can conflict, or with consensus, which costs a cross-region round trip per write.
Why are writes slow in a multi-region database?
Because a write must reach a leader or a majority of replicas, and regions are tens to hundreds of milliseconds apart: about 75 ms between Virginia and Ireland and over 200 ms between Virginia and Singapore. Placing each record’s leader in the region that writes it most keeps most writes local.
How do multi-leader databases handle write conflicts?
When two regions write the same record before seeing each other’s write, both are accepted and must be reconciled later, with last-writer-wins by timestamp, CRDTs that merge automatically, or application logic. Avoiding the problem by giving each record a single home region is often simpler.
How does Spanner or CockroachDB stay consistent across regions?
Each range of data is replicated with a consensus protocol such as Paxos or Raft, and a write commits only when a majority of replicas, in different regions, have it. A region can fail without losing acknowledged data, and placing leaders near writers keeps latency down.
What happens to writes when a region fails?
With asynchronous replication, writes acknowledged in the failed region but not yet replicated are lost, roughly the replication lag, and writes to data led there stop until a replica is promoted. With synchronous or consensus replication nothing acknowledged is lost, at the cost of slower writes.
What is data residency in multi-region design?
A legal or contractual requirement to keep certain users’ data within a country or region, for example under GDPR. Home-region placement, which stores each user’s records in one region, satisfies it naturally, while full replication everywhere may not.