← Backend Performance & Scaling learning path
Backend Performance & Scaling · Module 4 of 8

Caching

Remember answers so you do not compute them again.

📖 Key ideas

  1. A cache keeps recent results in fast memory, such as Redis, to avoid repeating slow work.
  2. Cache-aside: check the cache, and on a miss read the database and store the result.
  3. Every cached item needs an expiry (TTL) or a clear rule for when it is invalidated.
  4. Cache data that is read often and changes rarely; do not cache per-user secrets carelessly.
  5. Watch the hit ratio: a cache that is rarely hit only adds complexity.
💡 Real-life example: A cache is like a shopkeeper keeping the 20 best-selling items on the front counter instead of walking to the godown for every customer.
Cache hitThe answer was found in the cache
TTLTime to live: how long a cached item stays valid
Cache-asideRead cache first, fill it from the database on a miss
InvalidationRemoving or updating stale cached data