by Kondasamy Jayaraman

Module 21 · Caching & CDNs

Beginner · by Kondasamy Jayaraman

Why a copy nearby beats the original far away

A shop that answers every request from one place makes far customers wait, and buckles when everyone shows up at once. Here you put copies in Larkspur’s regional warehouses, then keep them right through a price change and a flash sale.

Read as

The whole idea in one example

One request from the West, two ways

From the depot

miss

128 ms

2,800 km to the depot and back.

From the shelf

hit

12 ms

A copy in the West warehouse, no trip.

Waits come from a simulated day: Larkspur’s own traffic and planning numbers, not a measurement of any real network or CDN.

How it works

Four ideas carry the module

  1. 1 Keep a copy

    A shelf near customers answers repeat requests

    HTTP caching (RFC 9111) calls a stored response fresh while its age has not yet passed its freshness lifetime, the time from when the origin made it to when it expires.

    Source, checked 24 October 2026

  2. 2 How long is it fresh

    A copy kept too long goes stale

    A max-age directive tells a cache to treat the response as stale once its age is greater than that many seconds (RFC 9111).

    Source, checked 24 October 2026

  3. 3 Take it back

    A purge drops the old copy everywhere

    MDN: there is no way to delete responses that an intermediate cache stored with a long max-age; a CDN that offers purging lets you cache aggressively and purge only when the content changes.

    Source, checked 24 October 2026

  4. 4 Everyone at once

    Customers asking together share one trip

    Fastly’s documentation describes request collapsing: one request goes to the origin, the others wait on a waiting list, and the one response is cached and served to all of them.

    Source, checked 24 October 2026

The story

Larkspur’s shop goes regional

Larkspur Supply Co.’s online shop runs from one depot; the team puts copies in three regional warehouses and keeps them right through a price change and a flash sale. You’re on the team that runs the shop.

Played Context engineering or Inference engineering? Chapter 6 shows their caches are the same trick.

876
requests in Larkspur’s day, the trace every chapter runs
3
regional warehouses, each with a shelf of copies
123
trips to the depot at the 12:00 sale, with no copies anywhere
71%
of requests served from a shelf by the best policy in chapter 7

Your path

The chapters

  1. Chapter 1

    Far is slow

    Why does a customer far from the depot wait longer?

  2. Chapter 2

    Keep a copy nearby

    What does a copy nearby save, and when does it still miss?

  3. Chapter 3

    How long is it fresh?

    How long should a copy count as fresh?

  4. Chapter 4

    Take it back

    How do you take back a copy you already handed out?

  5. Chapter 5

    Everyone at once

    What happens when everyone asks for the same thing at the same moment?

  6. Chapter 6

    The same trick everywhere

    Where else does the keep-a-copy trick show up?

  7. Chapter 7

    Set Larkspur’s cache policy

    Which policy keeps the most requests on the shelves within the limits?

Who it’s for

  • Engineers
  • Product managers
  • Analysts
  • No code needed

Anyone whose product serves pages, images or data to people spread out over a map, and who wants to know why a fast page can show an old price. No background needed.