The Cache-Aside Pattern: When the Application Owns the Cache

2026-05-21

Cache-aside (sometimes called "lazy loading") is the most common caching pattern in the wild — and the one most developers implement without realizing it has a name. The application code, not the cache, owns the read/write logic. The cache is a dumb key-value store sitting next to your database.

The flow:

Contrast this with read-through (the cache fetches from the DB itself) or write-through (the cache writes to the DB synchronously). Cache-aside keeps the cache stupid and the application smart.

Why delete instead of update on write? If two writers race, "last write wins" in the database may not match "last write wins" in the cache — you can end up with the cache holding stale data forever. Deleting forces the next read to repopulate from the source of truth. The tradeoff: the next reader pays the cache-miss tax.

Real example: A product page reads product:42 from Redis. Miss. App queries Postgres, gets the row, writes it back to Redis with a 5-minute TTL, returns it. Next 10,000 reads in the next 5 minutes are pure cache hits. When inventory changes, the inventory service deletes product:42. Next reader rebuilds it.

The pitfalls nobody warns you about:

Rule of thumb: Set a TTL that's at most 10x the acceptable staleness window. If users can tolerate 30 seconds of stale data, TTL of 5 minutes is fine — the cache catches normal load and the TTL bounds your worst case if invalidation logic has a bug. Always have a TTL, even when you also invalidate explicitly. The TTL is your insurance policy against the invalidation bug you haven't found yet.

Cache-aside works when reads dominate writes (say, 100:1 or more) and brief staleness is acceptable. Skip it for write-heavy workloads or anything requiring strong consistency.

See it in action: Check out Redis and MongoDB: Cache-Aside Pattern by Redis to see this theory applied.
Key Takeaway: The application — not the cache — owns the read-through and invalidate-on-write logic; always set a TTL as insurance against the invalidation bug you'll inevitably ship.

All newsletters