Loading lesson…
Level 1 · Apprentice0 XP
Answer from memory instead of asking again, and know when the memory is wrong.
Step 1 / 5
ProblemThe home page shows the top ten products. Every visitor triggers the same expensive query, and the result changes once an hour. The database spends its day recomputing an answer it already gave.
← → step
Before this: Stateless services
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Write getProduct(id) with cache-aside: read the cache, on a miss read the database and store the result for 60 seconds. Then write updateProduct so that the next read is never stale.