Notesreplication🌱 seedling

Read-Your-Writes Consistency

Also: Read-After-Write Consistency · Read Your Own Writes · Read My Writes

A session guarantee: after you write something, your later reads always reflect it. It promises nothing about other users' writes.

Why it exists

With asynchronous followers, you post a comment to the leader, reload, hit a lagging follower, and your comment is gone. Users read that as data loss.

How it works

  • Route by ownership: read things the user can modify (their own profile) from the leader; everything else from followers.
  • Route by recency: read from the leader for a window (say, a minute) after the user's last write, or skip followers lagging more than that.
  • Position tokens: the client remembers its last write's log position (a PostgreSQL LSN, a MySQL GTID); a follower serves the read only once it has replayed past it.
  • Wait at commit: PostgreSQL synchronous_commit = remote_apply returns only after synchronous standbys applied the write.

Trade-offs

Technique Cost
read from leader leader load; defeats read scaling if most things are editable
position tokens client or session must carry state; reads may wait
remote_apply higher commit latency

In practice

  • Cross-device read-your-writes (write on phone, read on laptop) needs the token on the server, and both devices routed to the same region.

Pitfalls

  • Remembering a wall-clock timestamp instead of a log position: clock skew makes it unreliable.

Recall

These cards are also in your review deck, scheduled with spaced repetition.