In this lesson · topic 1 of 7
Topic 1
One copy is not enough
4 min read
Why keep more than one copy
A database on one machine has two limits. If the machine dies, the data is unavailable until it comes back, and may be gone for good if the disk died with it. And one machine can only serve so many reads a second.
Replication addresses both. Keep the same data on several machines. If one dies, another can take over. Reads can be spread over all of them, which matters because most applications read far more than they write.
The usual shape: a leader and followers
The most common layout picks one machine as the leader. Every write goes to it. The leader records the write in an ordered log and sends the log to the other machines, the followers. Each follower applies the log entries in the same order, so it ends up with the same data.
Reads can go to the leader or to any follower. Followers are the point of the whole exercise, since they soak up read traffic.
What goes wrong
The followers are not instant copies. The log has to cross a network, and the network takes time and takes a different time on each trip. For a short while after a write, some followers do not have it yet. That gap is replication lag.
A read that lands on a follower during that gap returns an older value than the one the leader has already told someone was saved. You post a comment, the page reloads, and the comment is not there.
Predict first
In the lab’s simulation, 55%measured of reads from followers were stale with those settings. The leader had acknowledged the write each time. The follower just had not heard about it.
Two choices to make
When should the leader say yes? That sets write speed against the risk of losing data, and it should be a decision, not an accident. And how can each user keep a consistent view while followers disagree? The next topic takes both.