Cache or database?
| Dimension | Caching | Relational databases |
|---|---|---|
| Source of truth | No, a copy | Yes |
| Survives a restart | Maybe; assume it doesn’t | Yes, durably |
| Typical read latency | Under 1 ms | Milliseconds or more, depending on the query |
| Holds | What fits in memory | Terabytes on disk |
| Freshness | May be stale until TTL or invalidation | Current and transactional |
Rule of thumb
Design so the app still works, only slower, if the cache is empty. If losing the cache would lose data, it isn’t a cache any more.