Introduction to data replication
easy 25 minReplication keeps the same data on several machines and keeps the copies up to date.
When it comes up
The moments this idea belongs in a design interview, and the moments it does not.
Signals
When to bring it up
| You hear | Say | Because |
|---|---|---|
| The database must survive a failure | A standby in another zone, with tested failover | One server is a single point of failure |
| Mostly reads | Read replicas, and name the reads that must be current | Reads scale with copies |
| Mostly writes | Not replicas: scale up or shard | Every copy repeats every write |
| Users on two continents | Local read replicas, writes to one home | Distance costs at least 60 ms per 6,000 km round trip |
| Both regions must write while cut off | Multi-leader or leaderless, with a conflict rule | Somebody must decide what wins |
Options
Compare your moves
Reads are at 90% of what one database can serve. Writes are small. What do you do?
BreaksMake every server a leader
- How
- All nodes accept reads and writes.
- Limit
- You invent write conflicts to solve a read problem.
- Choose when
- Regions must accept writes on their own.
WorksA bigger machine
- How
- Scale the primary up.
- Limit
- Buys time, but there is still one copy and one point of failure.
- Choose when
- You need relief today.
StrongRead replicas with a routing rule
- How
- Add replicas, send reads that may be slightly old to them, keep current reads on the primary, watch the lag.
- Limit
- Some reads are old, so you must name which.
- Choose when
- Reads dominate and a small delay is acceptable for most of them.