Read-your-writes is a routing decision, not a database setting

route(read) = replica where pos >= w

Read-your-writes is a routing decision the application makes, not a database setting, because only the product knows which actions the user can observe.

A replica applies the leader's log later, so a read sent to it can return a value older than the user's own write. Read-your-writes is a routing promise: the reader carries the position of its last write, and the router sends that read only to a replica that has applied up to it. Without the check, the user sees their own action missing, and the product looks broken.

Consider a write followed by a read from the same user. The write lands on the leader, and the application records its position in the log in the user's session. When that user loads the profile, the router compares each replica's applied position with the stored one. A replica at or past that position answers. A replica behind it is refused, and if none qualifies the read goes to the leader, which holds the write. The check costs one comparison per read, so the router stays cheap. Nothing in the database changes, because the storage engine does not know this user exists. The whole guarantee lives in where the request is sent and what the router compares before sending it.

The abstraction hides the cost of the fallback and the failure of the stored position. Routing to the leader is correct, but it puts every read-your-writes request on the node that already handles all writes, so a busy product quietly moves read load there. The sharper failure is in the session. If the stored position is lost, say the user switches devices, the router has nothing to compare against. It then either sends the read to a replica, which may be behind, or sends everything to the leader. The first recreates the bug intermittently, because some requests land on a caught-up replica and some do not, so the report reads as flaky. Retrying the read hides it sometimes, which makes the bug look random. The second works but silently erases the capacity the replicas were added to provide.

Decide per read path before choosing any setting. List every screen that shows data a user just wrote, and ask whether that user could detect the order of their own actions going wrong. If the answer is yes, route that read through a position check or to the leader. If the screen shows data written by others, or the user cannot compare it against anything they know, leave it on a replica and accept the lag. Attach the position to the session at write time, not at read time, so the router has it. Keep the check at the routing layer, where the request is already sent, and test it by writing and then reading on a deliberately lagged replica. Record the decision next to the route so the next engineer does not reintroduce a plain replica read on the profile page.

orders of magnitude
replica lag
milliseconds to seconds

How far a follower trails the leader's log. A read from a lagging follower can return a value older than the user's own write.

position check
one compare per read

The router compares the stored log position with a replica's applied position. A single comparison per request adds little cost.

sticky routing
skew across replicas

Pinning a user to one replica keeps their reads moving forward, but load concentrates on whichever replica each user hashes to.

log sequence number
a point in the leader's log

Neon serves pages at a log sequence number, so a read can be answered as of one specific point and the storage layer returns exactly that state.

field note

The team treated a read replica as free capacity and sent every read there. Reads got cheaper and the dashboards looked healthy, so the change shipped without a second look at what the replicas were allowed to show. Nothing in the test suite wrote and then read, so the gap stayed invisible until real users touched the product.

The wall came the first time a user wrote and then read. The write landed on the leader, but the read hit a follower that had not applied it yet, so the screen showed the user's own action as missing. Refreshing sometimes fixed it, which made the bug look intermittent and sent the investigation toward network timeouts instead of routing.

The fix is a routing decision: the reader carries the position of its last write, and the router rejects any replica behind it. Neon's storage layer also serves pages at a log sequence number, so a read can name the point in time it needs. The lesson is that freshness is a property of each read, and only the product knows whether a user can observe the order of their own actions.