How it works
Lag can confuse even a user who never writes. Suppose follower A is 1 second behind, follower B is 5 seconds behind, and a load balancer picks either per request. A reader opens a comment thread through A and sees a comment posted 3 seconds ago. They refresh, land on B, and the comment is gone. Monotonic reads rule this out: once a reader has seen some state, later reads will not show an older one. The data may still be stale, but it does not move backward.
The usual fix is to pin each reader to one follower by hashing the user ID. If that follower fails, the reader moves to another that may be further behind, so the guarantee can break unless the reader also carries the log position it has seen.
Consistent prefix reads address a different anomaly: seeing an effect before its cause. A single log applied in order cannot do this, but shards have separate logs and no shared order. Say “order 77 created” goes to the orders shard and “refund for order 77” to the payments shard. If the orders follower is 4 seconds behind and the payments follower is current, a support dashboard shows a refund for an order that does not exist.
The simplest fix puts related writes on one shard, here by keying both on order ID. Otherwise, track dependencies and hold an event back until its cause is visible, or use a database that reads consistent snapshots across shards, as Spanner does, at a coordination cost.
A task-board product shards events by author. Ana creates a card, then Ben moves it to “done”. Viewers read from followers of both shards, and sometimes a board receives the move before the card exists and shows an error. Would you re-shard by board ID or add dependency tracking?
Re-shard by board ID if you can, since one board’s events then share a log and a follower applies them in order, which removes the anomaly without client logic. The cost is a data migration, and a very large board becomes a hot shard. If migration is too costly, have each event name the event it depends on and hold it back until that one is visible. That works across shards, but it adds buffering logic and metadata to every event.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Monotonic reads stop a reader seeing newer data and then older data.
- Pinning a reader to one follower gives monotonic reads until that follower fails.
- Consistent prefix keeps cause before effect; shards with separate logs can break it.