"There are only two hard things in computer science: cache invalidation and naming things." Interviewers know the joke, so when you add a cache to your design, expect the follow-up: how do you keep it from serving stale data? Here are the four strategies worth knowing, with the trade-off for each.
Every cache entry expires after a fixed time. It is simple and self-healing, but readers can see stale data for up to one TTL. Good for data where a few seconds or minutes of staleness is fine: product catalogs, profile pages, feed rankings.
The application reads from the cache, falls back to the database on a miss, and fills the cache. On a write, update the database first, then delete the cache key (don't update it). Deleting is safer than updating because two concurrent writers can otherwise leave the older value in the cache.
Write-through updates the cache and the database in the same request, so reads are always fresh but writes are slower. Write-behind writes to the cache and flushes to the database asynchronously: fast, but you can lose data if the cache node dies before the flush. Mention that risk explicitly.
The database publishes change events (for example via change data capture into Kafka), and a consumer deletes or refreshes the affected keys. This scales across many services that cache the same data, at the cost of extra infrastructure and eventual consistency.
Thundering herd: when a hot key expires, thousands of requests hit the database at once. Fix it with request coalescing (one request rebuilds, others wait) or by adding random jitter to TTLs.
Race between read-fill and write: a slow reader can put an old value back right after a writer deleted it. Short TTLs as a safety net, or versioned keys, close that gap.
Pick a default (cache-aside plus TTL), state the staleness you are accepting, then name the upgrade path if the interviewer pushes for stronger consistency. That shows judgment, not just vocabulary.
If you want live feedback while practising design rounds like this, I help build Linkjob AI, an AI interview assistant.
Disclosure: I'm part of the Linkjob AI team.
Further reading: Linkjob AI resource directory