Caching medium
Under what condition is 'Negative Caching' (caching a clear 'Not Found' signal) most beneficial?
- A When the underlying database is strictly read-only and uses a static dataset that never requires cache invalidation.
- B When lookups for non-existent items are computationally expensive and the same invalid keys are requested frequently.
- C When the cache memory utilization has reached its physical limit and the eviction policy is actively reclaiming space.
- D When the application utilizes a Write-Through caching pattern that ensures every database update is mirrored in the cache.
Answer: B. When lookups for non-existent items are computationally expensive and the same invalid keys are requested frequently.
**Negative Caching** (caching a 'Not Found' result) is critical when the cost of validating non-existence is high. For example, if a bot requests `user_id=99999`, and the DB must perform a slow scan to confirm this user doesn't exist, the system remains vulnerable. Caching `99999 -> null` for a short TTL protects the database from repeated expensive misses.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- In the Cache-Aside pattern, what happens when the application requests data that is missing from the cache (a 'Cache Miss')?
- Why use a centralized Distributed Cache (like a Redis Cluster) over local in-memory caches on each web server?
- Setting a short TTL (e.g., 60 seconds) on a cached object helps to:
- What is the primary architectural goal of introducing a cache into a system?
- Most caching systems rely on the principle of 'Temporal Locality', which states:
- Your cache uses an LRU (Least Recently Used) eviction policy. When the cache is full, which item is removed?