Cache vs Database
Compare fast temporary access layers with durable source-of-truth storage.
Architecture
Cache
A cache is a fast storage layer used to reduce latency and lower load on backend systems by storing frequently accessed data temporarily. It is usually optimized for speed rather than durability.
Architecture
Database
A database is the durable source of truth for application data. It is designed for persistence, consistency, structured access, and long-term data management.
Key Differences
A cache stores temporary or derived data for speed, while a database stores durable authoritative data.
Caches optimize low-latency reads and repeated access, while databases optimize persistence, integrity, and broader query capabilities.
Cache contents can often be rebuilt or repopulated, while database contents are usually business-critical data.
Caches reduce backend pressure, while databases hold the real application state.
Caches are often used for hot paths and repeated lookups, while databases remain the primary data system.
The distinction is acceleration layer versus source of truth.
When to Use
When to use a Cache
Use a cache when you need faster reads, reduced database load, repeated value reuse, session acceleration, rate limiting, or short-lived data access optimization.
When to use a Database
Use a database when data must be persisted reliably, queried correctly, and treated as the long-term source of truth for the application.
Tradeoffs
Caches improve speed, but add invalidation, freshness, and consistency complexity.
Databases provide correctness and persistence, but are usually slower than in-memory caches.
The strongest architectures often use both: database as source of truth, cache as acceleration layer.
Common Mistakes
Treating cache as the primary source of truth for important application data.
Adding a cache before understanding whether the database is actually the bottleneck.
Ignoring cache invalidation and consistency behavior.
Interview Tip
A strong short answer is: cache accelerates access, database persists truth.