Try
↑ ↓ move↵ openesc close

Interview prep / Replication and lag

Junior · Replication and lag · System design interview question

Your app has one leader and two read replicas that run a few hundred milliseconds behind. Which of these reads can go to a replica: the product catalogue page, the order confirmation page right after checkout, and the account balance shown before a transfer?

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

A strong answer

The catalogue page can. Products change rarely, and a view that is a few hundred milliseconds old is invisible to a shopper. It is also the highest-volume read, so moving it off the leader gives the most relief.

The order confirmation page should not, at least not straight away. The customer just wrote that order, and a replica may not have it yet, so they would see "order not found" seconds after paying. Read it from the leader, or from a replica only once it has caught up to the position of that order's write.

The balance before a transfer must come from the leader. The decision to debit depends on it, and acting on a stale number can allow an overdraft.

The sorting rule behind these three: reads whose staleness nobody notices go to replicas. Reads that must see the user's own just-written data, or that feed a decision about money or stock, go to the leader. It helps to tag each query in the code with how stale it may be, so the routing is a deliberate setting and not a habit.

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