Quick revision
The short answer
The invalidation reaches a remote region in 200 ms, but the next read there misses and loads from the local replica, which is still 1 to 2 seconds behind, so the old value is cached again for the full TTL. The fix is to invalidate relative to the data each region reads: drive a region's invalidations from its own replica's progress, or carry the new version in the invalidation and refuse to cache older values, or at least delete again after the maximum replica lag. Reads right after a user's own write go to the primary region or wait for a version token.
What to remember
In this answer, we saw that fast invalidation across regions can make things worse, because the remote cache reloads from a replica that has not yet received the change and caches the old value for a full TTL. The fix is to invalidate relative to the source each region reads from: generate invalidations from each replica's change stream or wait for its replay position, or carry versions and refuse to cache older rows, with a delayed second delete as a simpler fallback. Writers get read-your-writes through primary routing or version tokens, and we monitor replica lag and stale-read rates.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The invalidation reaches a remote region in 200 ms, but the next read there misses and loads from the local replica, which is still 1 to 2 seconds behind, so the old value is cached again for the full TTL. The fix is to invalidate relative to the data each region reads: drive a region's invalidations from its own replica's progress, or carry the new version in the invalidation and refuse to cache older values, or at least delete again after the maximum replica lag. Reads right after a user's own write go to the primary region or wait for a version token.
Why this question is asked
Multi-region systems surprise people because each piece works as designed: invalidations are fast, replication is fast, and still users see old data for minutes. Interviewers ask this to see whether we can reason about ordering between two independent pipelines. In this answer, we will walk through the race, see why speed does not help, look at three ways to tie invalidation to replication, handle read-your-writes, and decide what to monitor.
1Walking Through the Race
Region A holds the database primary. Regions B and C each have a read replica and their own Redis cache. A user in A updates a product at time 0. The change is committed in A, and an invalidation message is published to all regions.
At 200 ms, region B receives the invalidation and deletes product:5001 from its cache. At 300 ms, a user in B reads the product. The cache misses, so the service loads it from B's replica. But the replica will only apply the change at around 1,500 ms, so it returns the old row, and the service caches it with a 10-minute TTL. The invalidation has already been spent, and region B now serves the old product for 10 minutes.
6 messages in order. Play them, or step through them one at a time.
The invalidation arrived before the data did, so the old value was cached again.
2Why Faster Invalidation Does Not Help
The intuition says that invalidation should be as fast as possible. Here that intuition is wrong. The invalidation is useful only if, after it, a reload sees the new data. In region B, reloads read the replica, so the invalidation must happen after the replica has the change, not after the primary has it. Making the message faster only widens the window in which a reload fetches old data.
So the principle is: invalidate relative to the source your cache loads from. Each of the designs below is a way to apply that principle.
3Invalidating From Each Region's Replica
The most robust design generates each region's invalidations from that region's own replica. If the change stream is read from B's replica, an invalidation can only exist once B's replica has applied the change, so the race disappears by construction. PostgreSQL 16 and later can run logical decoding on a standby, which makes this possible with a CDC connector per region (check your version and connector support).
A lighter variant keeps one central change stream but makes each region wait. The invalidation message carries the commit's log position, its LSN, and the regional invalidator holds it until the local replica has replayed past that position.
The invalidator batches these checks, one query covers every waiting message, so the cost is small. Region B's invalidation now arrives at about 1,500 ms instead of 200 ms, which looks slower but is the first moment at which deleting the key actually helps.
4Versions in the Invalidation, or a Second Delete
If changing the pipeline is not possible, two cheaper defences help. The first carries the new version of the row in the invalidation. Region B stores a short-lived marker, min:product:5001 = 18, and when a reload produces a row older than 18, the service returns it to this one request but does not cache it. The next reload, after the replica catches up, gets version 18 and caches it. The cost is a version column on the data and an extra key read per miss.
The second is the delayed double delete: delete at 200 ms as now, and again after the maximum expected replica lag, for example at 3 seconds. Anything cached from the stale replica in between is removed by the second delete. It is simple, but it is a bet on the lag bound; when the replica falls 30 seconds behind during a heavy migration, the second delete fires too early as well.
| Design | Guarantee | Cost |
|---|---|---|
| Change stream per replica | Invalidate only after replica has data | CDC per region |
| Wait for replica LSN | Same, with one central stream | LSN in messages, replay checks |
| Version floor on reload | Never caches an older version | Version column, extra read on miss |
| Delayed second delete | Works if lag stays under the delay | Simple; fails under large lag |
5Read-Your-Writes for the User Who Wrote
Even with correct invalidation, the user who just saved a change in region B expects to see it at once, and B's replica may not have it for a second or two. Two common answers exist. Route that user's reads to the primary region for a few seconds after a write, for example by setting a cookie with the write time that the routing layer checks. Or return a version token, such as the commit LSN, with the write response; the client sends it with later reads, and region B serves from cache or replica only once its replica has reached that position, otherwise it waits briefly or reads from the primary.
Both affect only the writer's own requests, so the rest of the traffic keeps the low latency of local reads.
6What to Monitor
Replica lag per region is the first number, because it is the size of the race window. The second is the stale-read rate: a sampler that reads a small fraction of cached keys and compares them with the primary shows how often a region serves old data, which is the number users feel. And for data where cross-region staleness is costly, such as prices or permissions, TTLs should be short enough that even a missed invalidation heals quickly.
7Follow-up questions
What happens to this design during a regional failover?
If region A fails and B's replica is promoted, writes that A committed but had not yet replicated, the last second or two, are lost, while caches in some regions may already hold values from those lost writes. LSN tokens and version floors from the old timeline also no longer compare cleanly. The safe step after a failover is to bump a global cache namespace version, or flush the caches that could hold lost data, and to reset version floors, accepting a period of cold caches in exchange for consistency with the new primary.
Why not just use a short TTL in remote regions?
It limits the damage, but a TTL short enough to hide a 2-second race would be a few seconds, which destroys the hit ratio. Tying invalidation to replication keeps long TTLs and still avoids caching stale values.
Could we update the cache instead of deleting it?
Writing the new value into remote caches from the primary region avoids the reload from the stale replica, but it creates its own ordering problem: two updates in quick succession can arrive out of order and leave the older value cached. Deletes are idempotent and order-insensitive, which is why most designs delete and fix the timing instead.
8Conclusion
In this answer, we saw that fast invalidation across regions can make things worse, because the remote cache reloads from a replica that has not yet received the change and caches the old value for a full TTL. The fix is to invalidate relative to the source each region reads from: generate invalidations from each replica's change stream or wait for its replay position, or carry versions and refuse to cache older rows, with a delayed second delete as a simpler fallback. Writers get read-your-writes through primary routing or version tokens, and we monitor replica lag and stale-read rates.
Open with
The invalidation arrives in the remote region after 200 milliseconds, but the data arrives after one or two seconds. So the remote cache deletes the key, the next read misses, loads from the local replica that is still behind, and caches the old value again for the whole TTL.
Then, if they want more
Faster invalidation does not help; it makes the window bigger. The rule is to invalidate relative to the source the cache loads from.
The cleanest design generates each region's invalidations from its own replica, either with change data capture on the replica, which PostgreSQL supports on standbys since version 16, or by putting the commit LSN in the message and having the regional invalidator wait until pg_last_wal_replay_lsn has passed it.
Cheaper options are to carry the new version in the invalidation and refuse to cache a loaded row with a lower version, or to delete a second time after the maximum replica lag, which fails if lag spikes.
For the user who just wrote, I would route their reads to the primary region for a few seconds, or give them a version token the remote region must reach before serving. And I would monitor replica lag and a sampled stale-read rate per region, with short TTLs for data where staleness is costly.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- PostgreSQL 16
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Why can remote regions end up caching stale values even though invalidations arrive...": https://scrivio-interview-library.netlify.app/architecture/caching-strategies/5e11b47592/