Replication
Copies of your data.
If Shoply's only database server dies, every order is at risk. Replication keeps copies of the data on several machines, so one failure doesn't lose anything.

- One database, one risk
- Keep copies
- Survive a failure
Leader and followers
The most common setup is leader and followers. All writes go to the leader. The leader records each change in a log, and sends the log to its followers. Each follower replays the changes, so it holds the same data. If the leader dies, a follower can be promoted to take its place.
- Writes
- Leader
- Change log
- Followers
- Promote if needed

Sync vs async copies
Copies can be made in two ways. With synchronous replication, the leader waits until a follower confirms, before telling the user it's saved. That's safe, but slower. With asynchronous replication, the leader answers straight away, and followers catch up a moment later. It's fast, but a crash can lose the last few changes.
Synchronous
- Wait for the followerNo data lostSlower writes
Asynchronous
- Answer straight awayFastCan lose recent writes
Summary
Replication copies data to followers, for safety and for scale. Synchronous is safe, asynchronous is fast. Next, using those copies to handle more reads.
Key takeaways- Leader takes writes
- Followers copy the log
- Sync vs async