Why is cache invalidation considered hard? Give a concrete stale-read example.
basicThe cache and the database are two stores updated by separate operations that cannot be made atomic, so any ordering leaves a window where readers see old data or, worse, old data is stored permanently.
- Thread A reads a miss and loads value v1 from the DB. Thread B updates the DB to v2 and evicts the key. Thread A then writes v1 into the cache. v1 stays until the TTL expires.
- Every invalidation strategy only narrows the window; the TTL is the safety net that bounds how long staleness can last.
- Is a TTL enough? It bounds staleness but does not remove it; choose TTL by what the business tolerates.
- Does the stale value self-heal? Only on expiry or the next eviction.