Part 2 of 8 · 1 min read
Why keep copies
Three goals of replication and the idea of a replica.
Think of an important document kept in the office safe. One copy in the safe is lost in a fire. Copies in two offices survive. A copy kept in a branch office also saves staff there a long journey. The same document, kept in several places, serves three goals at once.
The book "Designing Data-Intensive Applications" gives the reasons for replication: keep data close to users to cut latency, keep the system working when some parts fail, and spread reads over more machines to raise throughput.
Replica and replication
A replica is a node that stores a copy of the database. Replication is keeping those copies in step with each other as the data changes.
Example: a user database runs on 3 machines. Each holds the full set of rows, so each is a replica.
If the data never changed, replication would be easy: copy it once and finish. The difficulty lies in handling changes. The book names three families of method: single-leader, multi-leader and leaderless. This page covers the first and most common. Modules 3 onwards cover the other two.
The three goals pull on the design in different ways:
| Goal | What replication gives | Cost |
|---|---|---|
| Availability | Another copy takes over if one machine fails | Failover is hard to get right (section 4) |
| Read capacity | Reads are spread over many machines | Copies can be behind (module 2) |
| Low latency | A copy near each group of users | Distance makes keeping copies in step slower |
Replication does not by itself solve a data set too large for one machine, since every replica holds all the data. That job belongs to partitioning (module 4).
Check yourself:
- Name the three goals of replication.
- Does replication help when a database is too big for one disk? Why?