System design

Stage 2 · Lesson 6 of 10

Replication and read replicas

Data storage, partitioning and replication

Replication keeps copies of the same data on several machines. That keeps data available when a machine fails and spreads out the reads. In , all writes go to one machine, the leader.

It streams its changes to followers, which serve reads. waits for a follower to confirm before telling the user the write worked. No data is lost if the leader fails, but writes are slower.

Asynchronous replication confirms straight away, which is faster, but a failover (switching to a follower) can lose the last few writes. Async followers fall behind, usually by milliseconds but sometimes by seconds. This is .

A user who posts and then reloads from a follower may not see their own post. Fix it with read-your-writes, for example by reading from the leader for a short time after a user writes.

Common trapadding to fix a write bottleneck: they only scale reads.

A question to check yourself, an AI practice session and 3 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

Also worth your time

Mark this stage as not done?