Distributed ReliabilityQueue recovery and health restorationPrincipal
How can policy reads guarantee read-your-writes across asynchronous replicas and transaction snapshots?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A policy edit commits on the primary, but the next verification or agent action reads an older rule from a replica. Design primary routing or a replay barrier with a valid commit marker, and explain why a timeout interval, old transaction snapshot or marker from a lost failover history can invalidate the guarantee.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Find out where the read went. A write can commit on the primary while an asynchronous read replica has not yet replayed that commit. The next request is routed to the follower and sees the previous policy. No database promise was violated if the application offered eventual follower reads, but the product may have promised that the editor could immediately verify or use the updated rule. PostgreSQL's hot-standby documentation describes the delay before changes become visible on a standby.
For read-after-write behavior, keep dependent reads on an authority known to include the write, or carry a safe commit-position fence and wait until the chosen replica has replayed at least that position. A temporary primary-routing interval is only a heuristic unless the route also proves replica freshness before returning to it. A fixed sleep is not a consistency guarantee. The replica might catch up quickly under normal load and lag much longer during failover or a heavy query. PostgreSQL's monitoring documentation distinguishes write, flush and replay lag. The relevant moment for a query is replay, when the change is visible there. The exact way to obtain and propagate a safe commit marker depends on the database driver and architecture.
The query also needs a sufficiently new transaction snapshot. A long repeatable-read transaction can retain a snapshot from before policy version 42 even after the standby has replayed its commit. Start a fresh eligible snapshot after the replay barrier rather than checking the replica counter while reading through an older transaction. PostgreSQL 18 isolation documentation explains that repeatable-read visibility remains tied to the transaction snapshot.
Obtain the marker through a database-supported protocol that is known to include this committed transaction. A position sampled before commit is not enough. Compare it only against a replica on the relevant authoritative replication history. After failover, verify that the promoted history contains the write. Numeric log-position comparison alone cannot recover an acknowledged commit that was lost. The application should wait, route to a verified authority or fail the freshness requirement visibly.
Separate three promises. The editor reading their own write may require a primary or a replay fence. Every user worldwide seeing the new policy at once requires a stronger publication barrier. An agent executing a high-impact action should check the authoritative policy version at the action boundary rather than trusting a convenient follower or stale search copy. If the service cannot reach a sufficiently fresh authority, decide whether to pause the action. A read-only dashboard can often show a clear staleness label instead.
A useful test writes policy version 42, immediately reads through each route, pauses replication, then triggers an agent action. Record which version the agent authorized against. A user updates a document and search answers from the old revision handles a user's document update waiting to reach the search index. This is a narrower database-read problem: primary commit succeeded, but the application read from a follower that had not applied it.
Related questions
Keep practising distributed reliability
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux