07 / 25 · Traffic and capacity

Caching

A cache keeps a reusable copy so future reads can avoid slower work. Copies can become stale or disappear. Decide what may be cached, for how long and who is allowed to read it.

What you will practise

  • Trace cache-aside hits/misses
  • reason about staleness
  • protect the cold-cache path

Before you start: Source of truth, key and expiry.

About 4 minutes · offline-generated English female narration · captions included. Diagrams are conceptual; timings are illustrative.

Download MP4Captions

Listen without the videoDownload audio

The same pre-recorded voice as the video. Starting audio pauses the video, and starting the video pauses audio.

Chapters and full transcript

Let us understand caching. You keep a timetable on your desk instead of walking to the office every time. It is fast, but a changed timetable makes your copy wrong. The expiry time tells you when to check again; it does not make the copy correct until then. A cache keeps a reusable copy so future reads can avoid slower work. Copies can become stale or disappear. Decide what may be cached, for how long and who is allowed to read it.

Follow the normal path. The reader asks for a public event description. The key identifies the resource and representation; private results need appropriate identity scoping. A reusable cached value returns quickly. Its age matters: a fast response can still be too stale for the business operation. SeatSpot event descriptions change rarely and are read often. They are good cache candidates. Available-seat ownership and payment outcomes need stricter correctness rules than a public description.

Now change one condition. If the value is absent or expired, fetch from the source of truth. A miss is normal and must have bounded latency and safe error handling. A common misunderstanding is this: A cache copy is always current until TTL expires. It can become stale immediately after a source update; expiry is not a correctness guarantee. Think about this. A popular key expires for every visitor at once. What load reaches the database? Pause the video and make your prediction. Many concurrent misses can refill the same value. Coalesce work, stagger expiry or serve controlled stale data where allowed.

Let us reason with a concrete example. An illustrative endpoint receives 1,000 reads/second with an 80% cache hit rate. About 200 reads/second reach the source in the simplified model. After a cache outage, the source may suddenly receive all 1,000. Test the cold-cache path, bound concurrent refill work and specify acceptable staleness for descriptions. Do not use the estimate to promise production capacity. These figures are teaching examples, not production guarantees.

Turn the idea into a design decision. Many readers may miss the same hot key together. Coalesce loads or bound refill work so the cache does not amplify pressure on the database. Populate the cache with an explicit lifetime. Plan what happens after an update and whether serving an older value is acceptable during refresh. When you try the practice task, look for this result. At 1,000 reads/second, source demand can jump from about 200 to 1,000 when the cache disappears.

Check your understanding. Remove the cache in a safe test. Observe source traffic, latency and errors. A warm hit-rate chart alone does not prove the architecture can recover. Here is a challenge. An event title changes but users still see the old title. Explain two remedies. Pause before the answer. Invalidate or version the affected cache entry on a successful update, or accept the documented TTL staleness. Consider races between refill and update; test the chosen consistency behavior. For an interview, choose key scope, invalidation and stampede control. Say what you would measure, not only which tool you would buy.

Start with an everyday picture

You keep a timetable on your desk instead of walking to the office every time. It is fast, but a changed timetable makes your copy wrong. The expiry time tells you when to check again; it does not make the copy correct until then.

Why SeatSpot needs this

SeatSpot event descriptions change rarely and are read often. They are good cache candidates. Available-seat ownership and payment outcomes need stricter correctness rules than a public description.

Trace one step at a time

Move through the diagram at your pace. Teal paths are active; unavailable components are labelled.

ReaderCacheSource DBRefill lockFresh response

Step 1 of 6 · Define the cache key

Request a description

The reader asks for a public event description. The key identifies the resource and representation; private results need appropriate identity scoping.

Read all six mechanism steps
  1. Request a description

    The reader asks for a public event description. The key identifies the resource and representation; private results need appropriate identity scoping.

  2. Serve a hit

    A reusable cached value returns quickly. Its age matters: a fast response can still be too stale for the business operation.

  3. Handle a miss

    If the value is absent or expired, fetch from the source of truth. A miss is normal and must have bounded latency and safe error handling.

  4. Control refill work

    Many readers may miss the same hot key together. Coalesce loads or bound refill work so the cache does not amplify pressure on the database.

  5. Store a temporary copy

    Populate the cache with an explicit lifetime. Plan what happens after an update and whether serving an older value is acceptable during refresh.

  6. Test a cold cache

    Remove the cache in a safe test. Observe source traffic, latency and errors. A warm hit-rate chart alone does not prove the architecture can recover.

Pause and make a prediction

A popular key expires for every visitor at once. What load reaches the database?

Answer aloud or write your reasoning in the lesson notes before revealing the explanation.

Correct a common misunderstanding

Claim to question: A cache copy is always current until TTL expires.

Better explanation: It can become stale immediately after a source update; expiry is not a correctness guarantee.

Trace a cache-aside sequence

A paper or whiteboard task. No cloud account or paid infrastructure is required.

  1. Write a cache key for a public event description.
  2. Follow miss → source read → cache write, then a hit.
  3. Remove the cache and estimate load at 80% previous hit rate.

Check what you can explain

This is your self-check, not an automated grade. Try again without the diagram tomorrow.

0 of 3 goals checked. Choose one remaining idea to practise next.

These checkboxes reset when you leave. Use your saved lesson notes and completion marker to record lasting progress.

Teach it back

Without looking, explain what this component changes, what it does not solve and what happens if it fails. Use the animation to check your explanation, then switch to Engineering.

Try it before viewing the solution

An event title changes but users still see the old title. Explain two remedies.

Check one key idea

When a cache disappears:

Your explanation and interview notes

Saved only in this browser when storage is available. Export a backup from the course page before clearing browser data or moving devices.

Loading your local notes…

Official references and next reading

The explanation, fictional examples and animations are original teaching material. Vendor behavior depends on the specific product/version; use its documentation before deploying.