The Most Common Pattern
How does data get into the cache? The most widely used strategy is Cache-Aside, also called Lazy Loading. The name "lazy" is intentional: data is only loaded into the cache when it is actually requested, not preloaded in bulk.
In this pattern, the application is responsible for talking to both the cache and the database. The cache itself has no knowledge of the database — it is just a fast key-value store. The application orchestrates everything.
How it Works: The Read Path
- The application needs data (e.g., User Profile for ID 123).
- It first checks the cache: "Do you have the key
user:123?" - Cache Hit: The cache has it. Data is returned instantly. The database is never contacted.
- Cache Miss: The cache does not have it. The application queries the primary database for User 123.
- The database returns the data to the application.
- The application writes that data into the cache under the key
user:123with a TTL (expiry time), so the next request will find it. - The application returns the data to the user.
Request for user:123
│
▼
┌───────────┐ HIT ┌──────────────────┐
│ Cache │────────▶│ Return to User │
└───────────┘ └──────────────────┘
│ MISS
▼
┌───────────┐
│ Database │
└───────────┘
│
▼
Write result to Cache
│
▼
Return to User
Pros and Cons
Pros:
- The cache only holds data that is actually being requested — no wasted memory on data nobody reads.
- Resilient to cache failures: if the cache goes down, the application falls back to the database automatically. The system degrades gracefully rather than failing completely.
- Simple to implement in any application layer.
Cons:
- The very first request for any piece of data is always slow (a cold start or cold cache problem). After a cache restart, all data must be re-warmed by real traffic.
- Data in the cache can become stale: if the database is updated (e.g., a user changes their name), the cache still holds the old value until the TTL expires or the cache entry is explicitly invalidated.
Interviewers frequently ask: "What happens when your cache goes down?" The correct answer for Cache-Aside is that the application automatically falls back to the database — this is the pattern's key resilience property. Contrast this with Write-Through, where a cache failure can block writes entirely if not handled carefully. Always mention that cache failures should be monitored and alerted on, even if they don't cause immediate outages, because the database will suddenly absorb 100% of traffic.