Why a confirmed order can disappear on refresh
Imagine a shopper who has just placed order 4821. Checkout returns an order number. The shopper follows the link to their order history, where yesterday’s purchase is still at the top. Refreshing a moment later reveals the new order. Both pages can be working exactly as their developers intended.
Checkout wrote the order to the primary database. The history page read from an asynchronous replica that was still applying earlier changes. PostgreSQL 19, released on November 19, 2026, adds WAIT FOR LSN. It lets the history page ask a specific standby to catch up to the checkout transaction before looking up the order.
Carry the commit position from checkout to the read
PostgreSQL records changes in its write-ahead log (WAL). A log sequence number (LSN) marks a position in that log. For order 4821, the application needs a position at or beyond the order’s commit record. Sampling it while the checkout transaction is still open can point to a moment before the order became visible.
After the commit succeeds, read pg_current_wal_insert_lsn() on the primary. Keep the result with the shopper’s server-side session for the next request. Other transactions may have advanced the log between the commit and the sample. That can add a little waiting, but the target still covers the order.
On the history request, reserve one connection to a standby. Run WAIT FOR LSN with that target before the first query on the connection. The default standby_replay mode waits for the replica to apply the changes. On success, fetch the order on that same connection. Handing the query back to a pool that can pick a different replica would lose the guarantee.
Give checkout a useful answer when replay is late
Set an explicit timeout. For example, if the confirmation page can spend 80 milliseconds waiting for replay, use that as its initial budget and measure the result. PostgreSQL waits indefinitely by default. With NO_THROW, the application can inspect the returned status and handle a timeout as an ordinary routing decision.
If the wait expires, fetch order 4821 by ID from the primary while the request still has time. If that lookup is temporarily unavailable, keep the confirmation number on screen and offer to refresh the details. Repeating the checkout write would turn a delayed read into a possible duplicate order.
Treat failover separately. An LSN is a numeric position and can occur on different database timelines. If the standby is promoted or the topology changes mid-request, recheck the order against the current authoritative database before reporting its status.
Test the screen the shopper actually sees
Use a disposable primary and standby in staging. Give each test order a unique reference so yesterday’s data or a cached response cannot make the test pass. Exercise the same redirect, connection pool and cache policy that the browser encounters after checkout.
- With replay caught up, submit an order and follow the confirmation link. The first response should contain that order’s reference and line items.
- Pause replay before checkout and hold it past the wait budget. Verify that the page follows the fallback path, still shows the reference and creates exactly one order.
- Resume replay and repeat with a fresh order. Record time spent waiting and the share of requests routed back to the primary. Those two measurements tell you what the freshness guarantee costs on this endpoint.
Key Engineering Takeaways
Related Radiaix Systems, Services & Technical References
The release date and the introduction of read-your-writes support for standbys.
Section 26.2.9 traces a committed write from the primary to a standby.
Command syntax, replay modes, return statuses and failover considerations.
How the checkout payload moves from the storefront into fulfillment.
Frequently Asked Questions
Which reads need this guarantee?
Use it where someone expects to see the result of their own action, such as opening an order just placed or reviewing an address just edited. A weekly sales chart can usually tolerate an older view. Reading directly from the primary is also a simple option for low-volume confirmation pages.
What if the confirmation page uses a cache?
A cache hit can bypass the database entirely. For the first confirmation read, bypass any cached order list or serve a cached result only if you know it includes the new order. Otherwise the shopper can still see an old response after the replica has caught up.



