Skip to content

Caching

A cache lets a system answer most requests without asking the database. That makes it faster, and it also lets you buy a smaller database. The cost shows up later: a copy that is out of date, an entry that expires at the wrong moment, a key that is too popular, or a cache that is gone. This module is about both halves: why caches work, and how they fail.

You will work with a live cache simulator, a capacity calculator, a trade-off explorer and a failure lab, and every lesson has a moment where you break something and see what happens.

  1. Cache-aside and the other read/write strategies (18 min). The hit ratio, why it matters so much, the four strategies and what each risks, and how much memory a cache needs.
  2. TTL and invalidation (16 min). How copies go stale, what a TTL promises, why deleting on write is not enough, and the race that beats it.
  3. Cache stampede (20 min). What happens when a popular entry expires, and three ways to stop it, each for a different cause.
  4. Hot keys (14 min). Why more shards do not help one dominant key, and what does.
  5. When the cache fails (22 min). Fail-open and fail-closed, the cascade, and a failure lab where you break Redis and repair it.
  6. Recap and quiz (12 min). The module in one page, a design checklist, and a quiz.
  • Work out how much load a cache takes off a database, and what happens to the database when the cache goes away.
  • Choose between expiring entries and deleting them, and say what each costs.
  • Recognise a stampede and a hot key, and choose a mitigation for the one you have.
  • Decide what an application should do when its cache is unreachable, and defend the decision with numbers.

All the numbers in the labs are illustrative. They are for comparing choices, not for forecasting any real product.

Built by GhaziAlibi.

© ShardCraft. All rights reserved.