Introduction to data replication
easy 25 minReplication keeps the same data on several machines and keeps the copies up to date.
Remember it
The few things worth knowing cold, and how to make them stick.
Memory hook
SAFE copies: Scale reads, Availability, Failover, Eventual or strong consistency.
Friends with copies of a treasure map. One friend draws new marks first and the others copy. If the first map is lost, another friend leads.
Cheat sheet
- Writes go to
- the primary (single leader)
- Reads can use
- any healthy replica, if old is fine
- Waiting for copies
- safer writes, slower
- Not waiting
- faster, last writes at risk
- Read capacity
- n (C - W)
- Conflicts
- multi-leader and leaderless
- Leaderless rule
- R + W > N
- Not a backup
- copies your mistakes
Spot it when you see
- The database must survive losing a server.
- Reads far outnumber writes.
- Users are far from the data.
- Reports slow down customers.
Tricks that stick
- Replica: same rows. Shard: some rows.
- One writer, no conflict.
- Copies scale reads, never writes.
Do not forget
- Reading your own write from a replica.
- Counting on replicas for write load.
- Calling a replica a backup.
- Choosing several leaders without a conflict rule.
- Letting the primary take all reads when replicas die.