Replication and durability
Keep data safe and available when machines fail.
15 min readMachines fail, data must not
Disks die, nodes reboot and whole data centres lose power. If your only copy of the data lives on one machine, any of these means downtime at best and permanent data loss at worst.
Replicas
Replication keeps copies of the data on several machines. A primary takes writes and streams them to replicas, which can serve reads and take over if the primary dies.
- Synchronous replication: no acknowledged write is lost, but writes are slower
- Asynchronous replication: fast writes, but the last few seconds can be lost on failover
- Automatic failover promotes a replica when the primary stops responding
Durability before acknowledgement
Never tell a user something is saved until it is stored durably. A chat message, an upload or a notification request should be written to a replicated store or a durable queue before you return success.
RPO and RTO
Recovery point objective (RPO) is how much data you can afford to lose; recovery time objective (RTO) is how long you can be down. They drive your choices: an RPO of zero needs synchronous replication; an RTO of seconds needs automatic failover.
Key takeaways
- Every stateful component needs at least one replica
- Acknowledge only after the data is durable
- State your RPO and RTO explicitly in your design decisions
Sign in to track lessons and earn badges.