BolEnglishLearn · Play · Win
Login

⚡ System Design · System Building Blocks

⚡

Caching

Building BlockCoreModule 3

Temporarily store frequently used data for faster access.

Avoid repeating expensive work when the answer has not changed.

💡 In practice

Cache a product catalog for five minutes instead of querying the database for every page view.

🖼️ CONCEPT PICTURE
A picture to help remember Caching
Cache a product catalog for five minutes instead of querying the database for every page view.

💡 Like keeping milk in the fridge instead of driving to the shop every time you want a cup of tea.

💡 Learn🛠️ Apply🎯 Check

💡 Why it matters

Fetching or computing the same answer over and over wastes time and overloads the database. A cache keeps a ready-made answer close by, so repeated requests are served instantly and the backend stays calm. The hard part is knowing when the cached answer is out of date, which is why caching needs care.

🛠️ How to achieve it

1
Cache read-heavy, stable data
Store results that are read often but change rarely, so most requests hit the cache.
2
Set a sensible expiry
Give each cached item a time to live that balances freshness against load.
3
Plan how to refresh
Decide how stale data gets updated or removed when the real data changes.
4
Handle a cache miss
When the cache has no answer, fetch it, store it, and serve it so the next request is fast.

⚠️ Signs of trouble

  • •The same expensive query runs again for every page view.
  • •The database is busy serving data that rarely changes.
  • •Users see stale data because the cache is never refreshed.
  • •A cache stampede hammers the database when many items expire at once.
⚠️ Common mistake: Caching data without a plan to refresh it, so users see stale information. Give each item an expiry and a clear rule for when to update it.

🎯 Quick check

Score: 0/3

Three questions to test the idea.

  1. 1. What kind of data is the best fit for caching?

    Answer: Data read often but changed rarely

    Read-heavy, rarely-changing data gives the most cache hits with the least risk of staleness.

  2. 2. What is the main risk of caching?

    Answer: Serving stale data if it is not refreshed

    A cache can hold an old answer, so you need an expiry and a refresh plan to keep it fresh.

  3. 3. What happens on a cache miss?

    Answer: The answer is fetched, stored, then served

    On a miss you fetch the real answer, put it in the cache, and the next request becomes a fast hit.

🔑 Key terms

Cache
A fast store holding ready-made answers.
Cache hit
When the answer is already in the cache.
Cache miss
When the answer is not cached and must be fetched.
TTL
Time to live: how long a cached item stays valid.

✅ Review checklist

📊 Your progress

0%
Mark this topic learned to track it.
Saved in this browser.
🚀 Got it?
Mark it learned and move to the next topic.
Next topic →