Opening Scenario
Your user profile endpoint used to respond in 12ms. After a product launch, traffic tripled and it now takes 400ms. The database is at 80% CPU. Adding more database read replicas helped temporarily, but the query is still being executed thousands of times per second for data that changes at most once an hour. Something is structurally wrong: you're repeatedly paying the cost of computation and I/O for results that don't change.
Question Progression
1. What problem does caching actually solve?
Question: Your user profile query hits the database and returns the same result for the same user 99.9% of the time. What's the real cost you're paying unnecessarily?
Reasoning: Each database query involves: network I/O to the database, disk I/O to read the row, CPU to parse and execute the query, and the return network trip. These costs are paid on every request,…
In the full tutorial
- When to Reach for Caching