How does cache-aside work?
Understand the concept
Cache-aside means the application manages when values enter and leave the cache. It first looks in the cache, loads missing data from the source of truth, then stores that result for later readers. This reduces repeated database work but creates a separate copy whose freshness must be controlled.
Important ideas
-
Read the cache first; on a miss, read the database and cache the result.
-
Expire or invalidate entries when data changes.
-
Use tenant-aware keys and avoid many requests rebuilding the same expired entry at once.
-
Use a TTL as a bound on staleness and consider single-flight loading or expiry jitter to reduce a cache stampede.
Cache-aside read flow:
- Build a key that identifies the resource and any user/tenant context.
- Read the cache; return the value if it is usable.
- On a miss, load the authoritative value from the database.
- Store it with a deliberate TTL, then return it.
- On writes, invalidate or update affected keys and account for concurrent readers.
Can you explain it without the notes?
How does cache-aside work?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Cache-aside means the application manages when values enter and leave the cache. It first looks in the cache, loads missing data from the source of truth, then stores that result for later readers. This reduces repeated database work but creates a separate copy whose freshness must be controlled.
Turn this concept into a clear answer.
- Explain the write path and invalidation race, not only the successful cache-hit path.
Adapted from 07_SYSTEM_DESIGN_ARCHITECTURE.md · “How does cache-aside work?”. Examples are study fragments; framework behavior can depend on your version.