Replication
Replication keeps copies of the same data on more than one machine. With async replication a copy can be 0.1 s behind, so a failover can lose the newest writes. Sync replication waits for a copy before it confirms, which adds a round trip to each write.
See it on the board
The same traffic runs on two boards. The simulator measured both when this page was built.
| Measure | Goal | Async copies, newest writes can be lost | Sync copies, each write waits for followers |
|---|---|---|---|
| Lost writes | none | 50 Fail | 0 Pass |
| Availability (Reads) | at least 100% | 100% Pass | 100% Pass |
| Availability (Writes) | at least 98% | 100% Pass | 98.3% Pass |
| p99 latency (Writes) | under 250 ms | 4.7 ms Pass | 105 ms Pass |
| CPU use | under 80% | 20.3% Pass | 20.3% Pass |
| Monthly cost | 24 USD/mo | 24 USD/mo | |
| Error rate | 0% | 1.7% |
Key numbers
| Number | Value |
|---|---|
| Delay of an async copy, default | 0.1 s |
| Write to disk on one copy | 0.4 ms |
| Round trip to a follower in one zone | 0.5 ms |
| Round trip to a follower in another zone | 1.5 ms |
Quorum 2 of 3 · commit 9.0 ms
How it works
A single database copy is a single point of failure. Replication sends each write from a leader to one or more followers. If the leader fails, a follower takes its place. Reads can also go to followers.
The key choice is when the leader confirms a write. With async replication, it confirms at once and sends the write to followers later. Writes are fast, but if the leader fails, the newest writes may not be on any follower yet. They are lost, although the client was told that they were safe.
With sync replication, the leader waits until the followers have the write. No confirmed write is lost, but each write waits for the slowest follower, and a follower that is down can stop all writes. Semi-sync waits for one follower only. It keeps one safe copy and accepts one slow follower.
Distance adds to the wait. A follower in the same zone adds about 0.5 ms to each write, and a follower in another zone about 1.5 ms. A follower on another continent adds tens of milliseconds.
In the levels you choose sync, semi-sync or async replication, and decide how many copies must confirm each write.