System DesignVol. 12 · Part XII
0 / 0

Shelves / System Design

SD·134

Global Systems

Designing for users and failures across the planet: why go global (latency, availability, residency), the physics of distance, geo-routing with DNS, anycast and global load balancers, latency-based and geo routing, regional failover and its pitfalls, cross-region replication (synchronous, asynchronous, consensus) and its costs, data locality and home regions, active-passive versus active-active topologies, conflict resolution for multi-region writes, globally distributed databases (Spanner, CockroachDB, DynamoDB global tables, Cosmos DB, Aurora Global Database), edge computing, and a step-by-step path to multi-region.

27 topics · ~17 min read · 30-question quiz
Updated Suggest a correction

Start here: the speed of light is a requirement

Going global means serving users on several continents, or surviving the loss of a whole region, or keeping data inside a country's borders. All three collide with physics: light in optical fibre travels about 200,000 km per second, so distance is latency, and no amount of engineering removes it.

Distance, in milliseconds

Great-circle distances from Hyderabad, and the best possible round trip through fibre (real routes are typically 1.5–2× longer):

Text
Mumbai          621 km     6.2 ms
Singapore     3,293 km    32.9 ms
Frankfurt     7,101 km    71.0 ms
N. Virginia  13,274 km   132.7 ms
São Paulo    14,289 km   142.9 ms

A page that makes five sequential calls to a server in Virginia spends at least two-thirds of a second just in transit for a user in Hyderabad. Global design is mostly about not crossing oceans inside a request: serving reads from nearby copies, caching at the edge, and keeping each user's writes in their home region.

What it costs to keep a second region in step

Every order commit, measured with the replica in a "second region" 70 ms away (round trip):

Text
async replica, same machine                         commit p50   0.49 ms
async replica, 70 ms away                           commit p50   0.88 ms
sync replica 70 ms away (remote_write)              commit p50  74.04 ms
sync replica 70 ms away (on, flushed)               commit p50  74.19 ms
sync replica 70 ms away (remote_apply)              commit p50  74.19 ms
sync replica, region 2 unreachable                  commit did not return within 5 s (writes blocked)

With asynchronous replication, commits stayed under a millisecond: the primary didn't wait for the far region. But if the primary's region is lost, the last moments of writes that hadn't crossed yet are lost too. With synchronous replication every commit waited for the far region, so each cost a full round trip (about 74 ms, 150× slower), and when the far region became unreachable, every write stopped. That is the global trade-off in one table: zero data loss across regions costs latency on every write and availability during a network split.

The options, in one line each

  • Active-passive: one region takes writes, others replicate asynchronously and take over on failure (accepting a small data-loss window, the RPO).
  • Read-local, write-home: each user's data has a home region; reads may be served nearby from replicas or caches.
  • Active-active with partitioned ownership: each region owns a slice of the data (e.g. Indian kitchens in Mumbai, European in Frankfurt), so most writes stay local.
  • Globally consistent databases (Spanner, CockroachDB, YugabyteDB): consensus across regions for every write, paying the round trip by design, often tuned by placing leaders near their users.

How deep to go in global systems

Volume 17 defines six mastery levels. For this chapter they look like this; the chapter aims at L3 everywhere, and its lab at L4.

Level What you can do
L1 Estimate latency from distance and explain why global systems are different
L2 Use CDNs, geo-DNS and regional replicas to serve users nearby
L3 Explain sync vs async cross-region replication, RPO/RTO, active-passive vs active-active, and residency
L4 Measure cross-region costs and failover behaviour, and find requests that cross regions needlessly
L5 Design a multi-region architecture with data ownership, failover and residency for a product
L6 Run a global platform: region strategy, disaster recovery programmes and compliance

Why go global

Three different motivations, which lead to different designs:

  1. Latency: users far from your only region suffer 150–300 ms round trips, multiplied by every sequential request (TLS handshakes, API calls). Serving from nearby regions or the edge cuts this.
  2. Availability / disaster recovery: surviving a region-wide outage (chapter 125).
  3. Data residency / sovereignty: regulations or customer contracts require data to stay in a jurisdiction (chapter 133).

Be clear which you need: static content latency is solved by a CDN alone; read latency by regional read replicas and caches; write latency and regional failure by much harder multi-region write architectures. Multi-region is expensive (duplicate infrastructure, cross-region data transfer, operational complexity), so choose the minimum that meets requirements.

The physics

Light in optical fibre travels at about 200,000 km/s, i.e. ~5 µs per km, and real routes are longer than great-circle distance. Rough round-trip times between major cloud regions:

Route Approx. RTT
Within an AZ < 0.5 ms
Between AZs in a region 0.5–2 ms
Mumbai ↔ Hyderabad / Delhi ~15–30 ms
Mumbai ↔ Singapore ~50–60 ms
Mumbai ↔ Frankfurt ~110–130 ms
US East ↔ US West ~60–75 ms
US East ↔ Western Europe ~75–90 ms
Mumbai ↔ US East ~190–220 ms
Sydney ↔ US West ~140–160 ms

Implications:

  • A synchronous cross-region write (waiting for another region's acknowledgement) adds at least one inter-region RTT to every write: 100+ ms for distant regions. Consensus across 3 distant regions costs at least the RTT to the nearest majority.
  • Chatty cross-region call patterns (a service in Europe calling a database in India per query) are disastrous: co-locate services with their data.
  • The speed of light won't improve; architecture must work around it.

Getting users to the right region

DNS-based routing

Managed DNS returns different answers depending on the client (Route 53, Azure Traffic Manager, NS1, Cloudflare load balancing, Google Cloud DNS routing policies):

Policy Behaviour Use
Geolocation Answer by the user's (resolver's) country/continent Residency, localisation, licensing
Geoproximity Answer by distance, with bias to shift traffic Gradual capacity balancing
Latency-based Answer with the region that has the lowest measured latency from the resolver's network Performance
Weighted Split by weights Gradual migrations, canaries
Failover Primary unless health checks fail, then secondary Active-passive DR

Limitations: decisions are based on the resolver's location (EDNS Client Subnet helps when supported), and caching/TTLs delay changes (seconds to minutes, sometimes longer with misbehaving resolvers or long-lived client connections).

Anycast and global load balancers

With anycast, the same IP address is announced from many locations via BGP; the internet routes each user to the nearest (in network terms) point of presence. Global load balancers (Google Cloud global external Application LB, AWS Global Accelerator and CloudFront, Azure Front Door, Cloudflare) use anycast front ends that terminate connections near users and forward traffic over the provider's backbone to healthy regional back ends, choosing by proximity, capacity and health in seconds without DNS caching delays.

users India users Europe users US edge (IN) edge (EU) edge (US) global LBhealth, loadproximity ap-south ✗unhealthy eu-central+ India traffic now us-easthealthy
Global traffic routing. Users connect to the nearest edge location via anycast; the edge terminates TLS, serves cached content, and forwards dynamic requests over the provider backbone to the nearest healthy region. If a region fails health checks, the global load balancer shifts its traffic to the next closest region within seconds; DNS-based routing achieves the same more slowly because of caching.

Latency-based routing in practice

  • Route reads to the nearest healthy region; route writes according to data ownership (below).
  • Measure real user latency (RUM) per region to validate routing; the "nearest" region geographically isn't always the fastest by network path.
  • Keep sessions valid across regions (stateless tokens, globally replicated session stores, or re-authentication) so failover doesn't log everyone out.

Regional failover

Failing over a whole region is the hardest operation in global systems. Pitfalls and practices:

  • Detection: distinguish a real regional failure from partial degradation or a monitoring problem; use multiple independent signals (synthetic probes from several locations, error rates, provider status). Many teams keep the decision human (with one-command execution) for region evacuation.
  • Capacity: the receiving region(s) must absorb the failed region's traffic: pre-provisioned headroom (static stability) or fast scaling. Cloud capacity in the target region may be constrained during large events.
  • Data: with asynchronous replication, the secondary may be seconds behind; failover loses those writes (RPO > 0) unless replication was synchronous; plan reconciliation for lost/divergent writes when the old region returns.
  • Dependencies: every dependency must exist in the target region (identity, secrets, queues, third parties, feature flags, CI/CD to deploy fixes). Hidden single-region dependencies are the most common failover failure.
  • Control plane independence: failover must not depend on the failed region's services (e.g. DNS hosted there, a deploy pipeline running there).
  • Failback: returning traffic after recovery is another risky migration (resync data, verify, shift gradually).
  • Practice: regular drills (game days, Vol. 11 ch. 120), ideally evacuating regions routinely (some companies shift traffic between regions daily, keeping failover a well-exercised path).

Cross-region replication

Mode Write latency RPO on region loss Consistency Examples
Asynchronous Local only Seconds of data (replication lag) may be lost Remote replicas stale by lag Aurora Global Database (typically < 1 s lag), PostgreSQL streaming replicas, Kafka MirrorMaker 2 / cluster linking, S3 Cross-Region Replication, DynamoDB global tables (default mode)
Synchronous (2 regions) + RTT to the other region 0 Strong Some database configurations; rarely used across distant regions due to latency and availability coupling
Consensus (≥ 3 regions) + RTT to nearest majority 0 Strong (linearizable) Spanner multi-region, CockroachDB, YugabyteDB, DynamoDB global tables with multi-Region strong consistency, Aurora DSQL multi-region

Consensus across regions tolerates a region failure while keeping strong consistency, at the price of write latency (place regions so a majority is close: e.g. two nearby regions + one tiebreaker), and reads that need leader leases or quorum round trips unless they accept bounded staleness.

Replication isn't only for databases: object storage, search indexes, caches (often rebuilt per region rather than replicated), message streams, secrets and configuration all need a cross-region plan.

Data locality and home regions

The most scalable global pattern is to partition data by geography or by owner so most operations are region-local:

  • Each user/tenant has a home region where their data lives and writes happen (recorded in a global directory; chosen by residency requirements or user location).
  • Requests are routed to the home region (or a nearby region forwards writes to it).
  • Data that is global by nature (product catalogue, configuration, public content) is replicated read-only to all regions from a single writer region.
  • Cross-region interactions (a user in one region messaging a user in another) are handled explicitly: asynchronous replication of the shared object, or one side's region owning it.

This "regional partitioning / home-region" approach gives local latency for most operations, avoids write conflicts (one writer per piece of data), and satisfies residency, at the cost of slower access when users travel and complexity for cross-region data.

Database support: CockroachDB REGIONAL BY ROW tables (each row homed in a region via a column), Spanner placement/geo-partitioning, YugabyteDB tablespaces with placement, DynamoDB tables per region with application routing.

SQL
-- CockroachDB multi-region: rows live in their home region; reads/writes there are local
ALTER DATABASE shop SET PRIMARY REGION "ap-south-1";
ALTER DATABASE shop ADD REGION "eu-central-1";
ALTER DATABASE shop ADD REGION "us-east-1";

CREATE TABLE users (
    id    uuid PRIMARY KEY DEFAULT gen_random_uuid(),
    email string UNIQUE NOT NULL,
    name  string
) LOCALITY REGIONAL BY ROW;          -- hidden crdb_region column decides each row's home

CREATE TABLE currencies (code string PRIMARY KEY, name string) LOCALITY GLOBAL;  -- fast reads everywhere

Active-passive vs active-active

Active-passive

One region serves traffic (or all writes); others are standby (warm or hot) with replicated data.

  • Simple consistency (single writer), simpler application logic.
  • Failover required on region loss (minutes, possible data loss with async replication).
  • Standby capacity mostly idle; risk that the passive region doesn't work when needed (test it!).
  • Variant: active-active reads, active-passive writes: all regions serve reads from local replicas; writes go to the primary region. Good for read-heavy global apps; write latency for far users.

Active-active

All regions serve reads and writes.

  • Best latency for everyone and fastest regional failover (traffic shift only).
  • Requires either partitioned ownership (home regions: each piece of data has one writer region, so no conflicts) or multi-writer data with conflict resolution, or globally consistent databases (consensus, paying write latency).
  • Each region needs capacity headroom to absorb others' traffic.
  • Operationally the most complex: deployments, schema changes, data migrations across regions; debugging cross-region anomalies.
active-passive region AprimaryR + W region Bstandbyreads only async failure → promote BRPO = replication lagRTO = minutes active-active AR + W BR + W CR + W home-region ownership: no conflicts multi-writer + conflict resolution consensus DB: strong, slower writes cost, complexity and availability all increase left → right
Active-passive versus active-active topologies. Active-passive sends all writes to one primary region with asynchronous replication to a standby, which is promoted on failure. Active-active serves reads and writes in every region; conflicts are avoided by home-region ownership of each record, resolved by merge rules for multi-writer data, or prevented by a consensus database spanning regions.

Conflict resolution across regions

When the same data can be written in multiple regions concurrently (multi-writer active-active, offline clients), conflicts must be resolved deterministically (chapter 129):

  • Last-writer-wins by timestamp: default in DynamoDB global tables (eventual mode), Cassandra, Cosmos DB default: simple, but loses concurrent updates and depends on clocks.
  • Custom merge procedures (Cosmos DB custom conflict resolution, application-level merges on read).
  • CRDTs for counters, sets, collaborative documents (Redis Enterprise Active-Active, Automerge/Yjs).
  • Avoidance: route all writes of a record to its home region; make the remaining multi-writer data naturally mergeable (append-only logs, per-region counters summed globally).
  • Constraints: global invariants (unique usernames, inventory limits) can't be enforced with independent regional writes: use a single authority for them (a global consensus-backed table, or region-partitioned namespaces like user@eu), or escrow (allocate inventory quotas to regions).

Design the data model so that genuinely conflicting concurrent writes are rare, and their resolution is acceptable to the business.

Globally distributed databases

System Model Notes
Google Spanner Consensus-replicated, externally consistent (TrueTime) SQL Multi-region configurations; strong reads from leader region or stale reads anywhere; geo-partitioning
CockroachDB Raft-replicated distributed SQL, serializable Multi-region abstractions (REGIONAL BY ROW, GLOBAL tables, survival goals ZONE/REGION)
YugabyteDB Raft-based distributed SQL (PostgreSQL-compatible) Geo-partitioning, xCluster async replication, read replicas
Aurora DSQL Serverless distributed SQL (PostgreSQL-compatible), active-active multi-region with strong consistency Optimistic concurrency; some PostgreSQL feature limitations
Aurora Global Database Single writer region + up to several read regions, storage-level async replication (typically < 1 s) Fast managed cross-region failover (switchover/failover); write forwarding from secondaries
DynamoDB global tables Multi-active key-value replication Eventual mode with LWW conflict resolution; multi-Region strong consistency mode (MRSC) using 3 regions
Azure Cosmos DB Multi-region writes, five consistency levels (strong, bounded staleness, session, consistent prefix, eventual) Session consistency default; conflict resolution policies
Cassandra / ScyllaDB Leaderless multi-datacenter replication LOCAL_QUORUM per region, tunable consistency, LWW

Choose based on consistency requirements, write latency tolerance, PostgreSQL/MySQL compatibility needs, operational model (managed vs self-hosted), cloud portability, and cost.

Edge computing

The edge (CDN PoPs, hundreds of locations) can run code close to users:

  • Edge functions (Cloudflare Workers, Fastly Compute, CloudFront Functions/Lambda@Edge, Vercel/Netlify edge, Akamai EdgeWorkers, Deno Deploy): request routing, authentication checks (JWT verification), redirects, A/B assignment, header manipulation, personalisation, image transformation, bot filtering, API aggregation.
  • Edge data: key-value stores with global replication (Workers KV: eventually consistent; Durable Objects: single-writer strongly consistent objects placed near their users; D1/Turso: SQLite with replicas), edge caches with tag-based purging.
  • Benefits: lowest latency for logic that doesn't need central data; offloads origins; global by default.
  • Limits: constrained runtimes (CPU time, memory, APIs), data still lives somewhere (calling a central database from the edge adds the long round trip back), debugging and observability across hundreds of locations, vendor-specific platforms.

Pattern: move read-mostly, latency-sensitive logic and data to the edge; keep authoritative writes in regions.

A path to multi-region

A pragmatic progression:

  1. Single region, multi-AZ, with a CDN for static/media content and good caching. (Most systems should stay here until requirements say otherwise.)
  2. Backups and infrastructure-as-code able to recreate the stack in another region (backup-and-restore DR); test it.
  3. Read replicas / caches in other regions for read latency; writes still go to the primary region.
  4. Warm standby region with continuous data replication and regular failover drills; global load balancing with health checks.
  5. Active-active for reads, home-region writes (partition by user/tenant geography) and region-local services.
  6. Full active-active with globally consistent databases or conflict-resolving data models where the business needs it.

At each step, make sure every dependency (identity, secrets, configuration, messaging, observability, deploy pipelines, third parties) is regional or global appropriately, the cost (duplicate capacity, cross-region transfer) is understood, and operations (deployments region by region, schema changes, incident response across time zones) are ready.

Lab: the price of a second region

A PostgreSQL 16 primary (port 5440) and a streaming replica (5441) on the lab machine, with the replica's primary_conninfo pointed at Toxiproxy 2.12, which added 35 ms in each direction (70 ms round trip) to stand in for a region roughly as far as Frankfurt is from Hyderabad. Each row is 40 single-row insert-and-commit operations from one connection. The honest limit: one machine with injected latency reproduces the waiting, not real WAN behaviour (packet loss, bandwidth limits, route changes), which make real numbers worse.

Experiment 1: commit latency by replication mode

SQL
alter system set synchronous_standby_names = '*';      -- any one standby must acknowledge
alter system set synchronous_commit = 'remote_write';  -- or 'on' (flushed) or 'remote_apply'
select pg_reload_conf();
Setup p50 p95
async, no added latency 0.49 ms 2.29 ms
async, 70 ms RTT 0.88 ms 2.49 ms
sync remote_write, 70 ms RTT 74.04 ms 75.60 ms
sync on (remote flush), 70 ms RTT 74.19 ms 76.99 ms
sync remote_apply, 70 ms RTT 74.19 ms 76.05 ms
sync, latency removed 1.19 ms 2.81 ms
sync, region 2 unreachable blocked (no return in 5 s) —

The three synchronous levels cost the same here because the replica's local work (write, flush, apply) is tiny next to the 70 ms round trip; across real regions, remote_apply adds the replica's replay time, which grows under load (chapter 127 measured 70 ms of replay lag under bulk writes). One connection doing sequential commits at 74 ms each manages about 13 commits per second; throughput across many connections still scales, because PostgreSQL groups waiting commits, but every individual user waits.

Experiment 2: the partition, and what to do about it

With synchronous_standby_names = '*' and the only standby unreachable, commits wait forever (until the standby returns or the setting changes). Production configurations avoid that single dependency with quorum sync, synchronous_standby_names = 'ANY 1 (mumbai_b, frankfurt_a)', so a nearby standby in another zone usually satisfies durability while the far one replicates asynchronously, and with automation (Patroni, CloudNativePG) that can relax synchronous mode when standbys vanish, which is itself a choice to accept data-loss risk. Write down which you've chosen: it decides your RPO.

Experiment 3: physics as a design input

From Hyderabad to Distance Best-case RTT 5 sequential calls
Mumbai 621 km 6.2 ms 31 ms
Singapore 3,293 km 32.9 ms 165 ms
Frankfurt 7,101 km 71.0 ms 355 ms
N. Virginia 13,274 km 132.7 ms 664 ms
São Paulo 14,289 km 142.9 ms 715 ms

Distances are great-circle; real paths add 50–100%, and TLS and TCP handshakes add round trips of their own for new connections (TLS 1.3 needs one, QUIC/HTTP/3 can resume with zero). Hence the usual global toolkit: terminate TLS and cache at the edge (CDN, anycast), keep connections warm, batch calls, and place data and compute in the user's region.

Experiment 4: a global design for the tiffin centre

Data Placement Replication Why
menus, images CDN + regional caches async, TTLs read-heavy, staleness fine
customer accounts home region by country async to a DR region residency, local writes
orders and payments kitchen's region sync to a second zone in-region, async cross-region low RPO without ocean round trips
analytics central warehouse async pipelines latency-insensitive

Try it yourself

  1. Configure ANY 1 (…) with two standbys, one at 2 ms and one at 70 ms, and measure commit latency. Then make the near one unreachable.
  2. Measure how long the replica takes to become a usable primary (pg_ctl promote) and what writes are lost if the primary is killed under load with async replication.
  3. Add 1% packet loss in Toxiproxy (there's no direct toxic; approximate with timeout or slicer) and observe tail latency.
  4. Sketch a partitioned-ownership design for orders in India and Europe, including what happens to a customer who travels.

Revision sheet: global systems

Key ideas

  • Why global: latency for distant users, regional disaster tolerance, data residency and sovereignty.
  • Physics: ~1 ms RTT per 100 km of fibre at best; routes add 50–100%; handshakes add round trips.
  • Traffic routing: geo-DNS, latency-based DNS, anycast, global load balancers; health-based failover and its DNS-TTL lag.
  • Edge: CDNs for static and cacheable content, TLS termination near users, edge compute for simple logic.
  • Data: active-passive (async, RPO > 0), synchronous within a region across zones, partitioned ownership (home regions), globally consistent databases (consensus per write).
  • Conflicts in multi-writer designs: avoid by ownership; otherwise last-writer-wins (lossy), CRDTs, or application merges.
  • DR: RPO and RTO targets, runbooks, regular failover drills, regional independence of dependencies (auth, DNS, secrets).
  • Residency: per-tenant or per-user region pinning; keep PII in-region; replicate only what's allowed.

Numbers to remember

  • Hyderabad → Frankfurt ≈ 7,100 km ≈ 71 ms best-case RTT; → N. Virginia ≈ 133 ms.
  • Lab: async commit 0.9 ms with a 70 ms-away replica; sync commit 74 ms; sync with the replica unreachable: writes blocked.

Pitfalls

  • Chatty request paths that cross regions several times.
  • Synchronous cross-region replication with a single standby (writes stop on a partition).
  • Failover plans that depend on a service hosted only in the failed region.
  • Active-active without a conflict strategy.
  • Ignoring residency for logs, backups and analytics copies.
  • Never practising regional failover.

Glossary

  • RPO / RTO: recovery point (data loss) / recovery time objectives.
  • Anycast: one IP announced from many locations; routing picks the nearest.
  • Home region: where an entity's authoritative data lives.
  • CRDT: data type whose replicas merge without conflicts.
  • Data residency: legal or contractual requirement on where data is stored.