Cache-aside (lazy loading) puts the application in control: on a read, it queries the cache; on a hit it returns immediately; on a miss it reads the database, populates the cache, then returns. Only data that is actually requested gets cached, keeping the cache small and relevant. The downsides: the first request for any item always misses (cold cache), and the cache can serve stale data unless you invalidate on writes. It is the most common caching pattern because it is simple and resilient — if the cache fails, the app still works (just slower).
2 / 5
What is the difference between write-through and write-back caching?
Write-through updates the cache and the backing store in the same operation: data is always consistent and the cache is never stale, but every write pays the cost of writing to both. Write-back (write-behind) updates the cache immediately and defers the database write (batched/async): writes are very fast and you can coalesce many updates, but if the cache crashes before flushing, unwritten data is lost. The choice is a classic durability-vs-latency trade-off; write-back suits high-write workloads that can tolerate some risk, write-through suits correctness-critical data.
3 / 5
What does TTL (Time To Live) control in a cache?
TTL is the expiry duration assigned to a cached entry. After the TTL elapses, the entry is considered stale and is either evicted or refreshed on next access. TTL is the primary lever for balancing freshness against load: a short TTL keeps data current but increases backend hits; a long TTL reduces load but risks serving outdated data. It is the simplest invalidation strategy — "let it expire" — and is often combined with explicit invalidation on known writes for data that must be fresh immediately.
4 / 5
What is an eviction policy such as LRU, and why is it needed?
Caches have bounded memory, so when full they must evict something to admit new data. The eviction policy decides what to drop. LRU (Least Recently Used) discards the entry untouched for the longest time, betting that recently-used data is likely to be used again. Other policies: LFU (Least Frequently Used) tracks access counts; FIFO evicts the oldest inserted; TTL-based evicts expired entries first. Choosing the right policy depends on access patterns — LRU is a strong, common default.
5 / 5
What is a cache stampede (thundering herd) and how can it be mitigated?
A cache stampede happens when a hot entry expires and a flood of concurrent requests all miss at once, hammering the database with identical expensive queries — potentially overwhelming it. Mitigations: request coalescing / single-flight (only one request recomputes while others wait for the result), locking on the key during refresh, staggered/jittered TTLs so many keys do not expire simultaneously, and stale-while-revalidate (serve the slightly-stale value while one background request refreshes). These prevent a single expiry from cascading into an outage.