Sub topic 7
Replicating Data Across Regions
This chapter assumes you know basic DNS and load balancing, and that you have worked with relational or NoSQL databases. It covers how data moves between regions and what each choice costs you.
Why replication is the hard part
Stateless compute is easy to run in many regions. Data is not. Every region needs a local copy to serve reads quickly, and in active-active every region also accepts writes. Replication is the process that copies each write to the other regions. How it copies decides your consistency, your latency, and your data loss on failure.
Synchronous and asynchronous replication
Synchronous replication waits for remote regions to confirm a write before telling the client it succeeded. Asynchronous replication confirms locally and ships the write afterward.
| Property | Synchronous | Asynchronous |
|---|---|---|
| Write latency | Adds a cross-region round trip | Local latency only |
| Data loss on region failure (RPO) | Near zero | Up to the replication lag |
| Availability during a link failure | Writes may block | Writes continue |
| Typical conflicts | None | Possible with multiple writers |
Cross-region round trips take tens to hundreds of milliseconds. Most active-active systems therefore use asynchronous replication and accept a small, measurable lag.
Common topologies
- Single-writer with read replicas: one region takes writes, the others serve reads. This is simple, but it is closer to active-passive for writes.
- Multi-leader: every region accepts writes and replicates them to all the others. This gives local write latency, and it can produce conflicts.
- Leaderless or quorum-based: a write goes to several replicas, and the client or coordinator decides success by quorum. Managed stores such as DynamoDB global tables use a multi-leader model with last-writer-wins resolution.
Conflicts
With multi-leader replication, two regions can change the same record before either sees the other's change. Those are concurrent writes. You have three options:
- Avoid them by giving each record a single owning region. The next chapter covers this.
- Resolve them automatically with a deterministic rule. Last-writer-wins and CRDTs are covered later.
- Detect them and ask the application or a person to decide.
The rule must give the same result in every region regardless of arrival order. If it does not, the copies diverge permanently.
Replication lag in practice
Lag causes visible anomalies. A user writes in one region, is routed to another, and does not see their own change. Common mitigations:
- Pin a user's session to the region that took their last write for a short window.
- Read from the writing region when read-your-writes matters.
- Return a version token with each write and wait until the local replica reaches that version before reading.
Common errors
- Assuming a managed "global" database is strongly consistent. Check its documented conflict rule and lag.
- Replicating schema changes carelessly. A migration that one region cannot apply stalls replication for the whole table.
- Ignoring replication of deletes. Without tombstones (markers recording that a record was deleted), a delete can be undone by a stale copy.
- Using wall-clock time for ordering without allowing for clock drift between regions.
Exercise
A user updates their profile in eu-west-1, and a second later their next request lands in us-east-1 and shows the old profile. Which replication mode caused this, and name one mitigation.
Show answer
Asynchronous replication, where the write had not yet reached us-east-1. Mitigations include pinning the session to the writing region for a short window, reading from the writing region, or waiting for a version token to arrive at the local replica before reading.