Try
↑ ↓ move↵ openesc close

Interview prep / Replication and lag

Mid · Replication and lag · System design interview question

What are monotonic reads, how can replication break them, and how do you guarantee them?

Sketch your own answer first, then compare it with the one below.

A strong answer

Monotonic reads says that once a client has seen a value, later reads by that client never return an older one.

Replication breaks it when successive reads land on different followers with different lag. The first read hits a follower that is current and the second hits one that is behind, so the client appears to go back in time. A comment appears and then vanishes on refresh.

The simple fix is to pin each client or session to a single follower, for example by hashing the client id, because one follower only moves forward. If that follower fails the client moves to another and may see a step back once. A stronger method has the client remember the highest log position it has seen and require followers to be at least that far along.

Pinning does not give read-your-writes, because the pinned follower can still be behind the client's own write. The two guarantees are separate, and a store can offer both.

Sources

Learn it by running it

The replication and lag lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms