← Lessons

quiz vs the machine

Platinum1800

Databases

Cache as a Database Antipattern

Why treating a volatile cache as the source of truth goes wrong.

5 min read · advanced · beat Platinum to climb

Cache as a Database Antipattern

A cache is a fast store that holds copies of data to speed up reads. Treating that cache as the source of truth, the place where data really lives, is a well known antipattern that leads to silent data loss and confusion.

Why it breaks

A cache is built for speed, not durability, and it makes assumptions that a database of record must not:

  • It may evict entries when memory fills, dropping data you needed.
  • It is often volatile, so a restart wipes everything.
  • It may lack durability guarantees, so a confirmed write can vanish.

If the cache is the only home for data, any of these silently destroys records that no other store can recover.

The right pattern

Keep a durable database as the source of truth and put the cache in front of it. On a read miss, load from the database and populate the cache. On a write, update the database and invalidate the cache. The hard part, often summarized as the two hard things in computing, is keeping the cache and database in sync, which is cache invalidation.

Key idea

A cache is a fast copy, not a system of record; keep a durable database as the source of truth and let the cache front it, with careful invalidation.

Check yourself

Answer to earn rating on the learn ladder.

1. Why is making a cache the source of truth dangerous?

2. What is the correct relationship between cache and database?

3. What is the hard sync problem called?