AlgoViz

Introduction to data replication

easy 25 min

Replication 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 hearSayBecause
The database must survive a failureA standby in another zone, with tested failoverOne server is a single point of failure
Mostly readsRead replicas, and name the reads that must be currentReads scale with copies
Mostly writesNot replicas: scale up or shardEvery copy repeats every write
Users on two continentsLocal read replicas, writes to one homeDistance costs at least 60 ms per 6,000 km round trip
Both regions must write while cut offMulti-leader or leaderless, with a conflict ruleSomebody 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.