Scrivio Interview library
DebuggingFoundations6 min read · updated 13 November 2026

A forum reads comments from three asynchronous replicas behind a round-robin pool. Users report that a new comment appears, disappears on the next refresh, then appears again.

Which consistency guarantee is missing, why does round robin cause it, and what is the simplest fix?

The missing guarantee is monotonic reads: once a user has seen some state, later reads should never return an older one. The replicas lag by different amounts, so one refresh hit a replica that had applied the comment and the next hit one that had not. The simplest fix is to pin each user or session to one replica, for example by hashing the user id, and fall back to another only when the pinned one is unhealthy; carrying the last seen log position and reading only from replicas at or past it closes the remaining gap when the pinned replica changes.

Why this question is asked

A comment that appears, vanishes and comes back makes users think their data is being lost, even though nothing is. Interviewers use this symptom because it maps to one specific, named guarantee, and the simplest fix is a one-line change in how reads are routed. In this answer, we will recap the consistency guarantees involved, show how round robin creates the flicker, apply the pinning fix, close its one remaining gap with log positions, and separate monotonic reads from read-your-writes.

1A Quick Recap: Asynchronous Replicas Lag by Different Amounts

The forum writes comments to a primary database, and three replicas receive the changes asynchronously. Each replica applies changes in order, but at its own pace: one might be 50 milliseconds behind, another two seconds behind while it runs a heavy report. A round-robin pool sends the first read to replica 1, the next to replica 2, the next to replica 3, and so on, without any memory of what each user has seen.

Several named guarantees describe what readers of such a system may expect. Read-your-writes promises that users see their own writes. Monotonic reads promises that a user who has seen a state never sees an older one later. Consistent prefix promises that writes appear in order. Round robin over lagging replicas gives none of them by default.

2How Round Robin Produces the Flicker

A user loads the thread, and the request goes to replica 1, which is 50 milliseconds behind and already has the new comment. On refresh, the request goes to replica 2, which is two seconds behind and does not have the comment yet: from the user's point of view, the comment disappeared. On the next refresh, replica 3 has caught up, and it is back.

Each replica is internally consistent; the problem is that consecutive reads from the same user go to replicas at different points in time. Time effectively moves backwards for that user, which is precisely what monotonic reads forbids.

Step throughRound robin over replicas with different lag
UserReplica 1 (50 ms)Replica 2 (2 s)Replica 3
load thread
comment visible
refresh
comment missing (older state)
refresh
comment visible again

6 messages in order. Play them, or step through them one at a time.

Every replica is correct for its own point in time; the user jumps between points.

3The Simplest Fix: Pin Each User to One Replica

If all of a user's reads go to the same replica, the user sees that replica's history, which only moves forward. So instead of round robin, we choose the replica by hashing the user id, or the session id for anonymous visitors. If the pinned replica is unhealthy, we fall back to the next one in a fixed order.

Java
DataSource replicaFor(long userId) {
int n = replicas.size(); // 3
int start = Math.floorMod(Long.hashCode(userId), n); // user 1042 -> 1, always the same
for (int i = 0; i < n; i++) {
DataSource ds = replicas.get((start + i) % n);
if (health.isUp(ds)) return ds; // replica 1 while it is healthy
}
return primary; // no healthy replica: read the primary
}

The load stays balanced because users are spread evenly across replicas by the hash. Notice that this changes nothing for writes and needs no coordination between replicas. It is a routing decision in the application or in a proxy, and it usually removes the flicker immediately.

4Closing the Gap When the Pinned Replica Changes

Pinning has one remaining hole. When a user's replica becomes unhealthy and we fall back to another one, the new replica may be further behind, and the user can go back in time once. For most forums that is acceptable. If it is not, the client or session remembers the last log position it has seen, and we only read from replicas that have replayed at least that far.

In PostgreSQL, every response can include the replica's replay position, pg_last_wal_replay_lsn(). The session stores the highest one. Before reading from a replica, the router checks that the replica's replay position is at or past the stored one; if none qualifies, it waits briefly or reads from the primary. In MySQL, the equivalent position is a GTID set, and WAIT_FOR_EXECUTED_GTID_SET can make a replica wait until it has applied it.

SQL
-- on the replica that served the last read
SELECT pg_last_wal_replay_lsn(); -- 5C/1A2B3C40, stored in the session
-- before the next read, on a candidate replica
SELECT pg_last_wal_replay_lsn() >= '5C/1A2B3C40'::pg_lsn; -- false: too far behind, try another

5Monotonic Reads Is Not Read-Your-Writes

Monotonic reads is weaker than it looks. It promises that a user never sees older state than they already saw, but not that they see their own new comment at once. If the user posts a comment and their pinned replica is two seconds behind, the comment is simply missing until that replica catches up; at least it will not flicker afterwards.

Read-your-writes needs other techniques, such as reading from the primary for a short window after the user writes, or carrying the write's commit position and reading only from a replica that has reached it. The position-tracking approach above gives both guarantees if we also record the position of the user's own writes.

6Follow-up questions

Why not just send all reads to the primary?

It would remove the flicker, but the replicas exist because the primary cannot carry all the reads. Pinning keeps the read capacity of the replicas and removes the anomaly at almost no cost.

Does sticky load balancing at the HTTP level give monotonic reads?

Only if the application instance also pins its database reads. Sticky sessions keep a user on one application server, but that server may still round-robin across replicas, so the database routing must be pinned too.

What guarantee does pinning give for writes by other users?

None beyond what the replica offers: the user sees other users' comments as the pinned replica receives them, in order and never going backwards, but possibly delayed.

7Conclusion

In this answer, we saw that the flicker is a violation of monotonic reads: round robin sends a user's consecutive reads to replicas with different lag, so their view jumps backwards. Pinning each user or session to one replica, chosen by hashing the user id, removes it, with a fallback when that replica is unhealthy. Carrying the last seen log position closes the one remaining gap when the pinned replica changes. Monotonic reads does not promise that users see their own writes immediately; that is read-your-writes and needs its own technique.

What to say in the interviewAbout 100 seconds aloud

Open with

The missing guarantee is monotonic reads: once a user has seen a state, later reads should not show an older one. The replicas are asynchronous and lag by different amounts.

Then, if they want more

With round robin, the first load went to a replica that already had the comment, the refresh went to one that was two seconds behind and did not, and the next refresh went to one that had caught up. Each replica is fine on its own; the user is jumping between different points in time.

The simplest fix is to pin each user, or each session for anonymous visitors, to one replica, for example by hashing the user id modulo the number of replicas. That replica's history only moves forward, so the user never goes back in time, and the hash still spreads load evenly.

If the pinned replica is unhealthy, we fall back to the next one in a fixed order. That fallback is the one remaining gap: the new replica might be further behind, so the user could go back once.

If that matters, the session stores the last replay position it saw, pg_last_wal_replay_lsn in PostgreSQL or a GTID set in MySQL, and we only read from replicas at or past it, otherwise from the primary.

I would also point out that monotonic reads is weaker than read-your-writes: it does not promise a user sees their own comment immediately, only that it will not disappear once seen. Read-your-writes needs reading from the primary after a write, or tracking the write's position.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Which consistency guarantee is missing, why does round robin cause it, and what is the...": https://scrivio-interview-library.netlify.app/architecture/partitioning-and-replication/ad61d7878a/