Learn

VISUAL GUIDE · SCALING & CACHING

Where a cache helps (and where it lies)

Recap

THE WHOLE PICTUREORIGINAL SKETCH
GET /abc123get, set on missread aliasdisabled?purgedisableBrowserRedirect serviceAlias cacheTTL 60 s!Alias storesource of truthDisabled listsmall, replicatedchecked every timeOwner ormoderator
A browser asks a redirect service for a short link; the service checks a cache, falls back to the alias store on a miss, checks a disabled list, and a link owner or moderator can edit the store, purge the cache, or disable a link.
Recap
  1. No cache
  2. Add a cache
  3. Cache hit
  4. Cache miss
  5. Link changes
  6. Stale hit
  7. TTL bounds it
  8. Purge
  9. Deny-list

RECAP

What to remember

  • A cache hit protects the store; the speed-up is a bonus.
  • On a miss the service reads the store and fills the cache, so a cold or expired hot key can send a burst of misses to the store.
  • Any change to the source of truth leaves cached copies stale until they expire or are purged.
  • The TTL is the worst-case staleness. Write first, then purge, and keep the TTL as the safety net.
  • For answers that must never be served (a takedown), check a small list on every request rather than trusting every cache to be purged.

NOW CLOSE THE GUIDE AND REDRAW IT

From memory, draw the read path for a short-link redirect with a cache. Then explain, on the same page, what happens when a cached redirect needs to change: once for an ordinary edit and once for an urgent takedown.

Check your drawing against this list afterwards, not before:

  • Browser, redirect service, cache and alias store, with the cache checked first.
  • The miss path: read the store, fill the cache, answer.
  • A TTL written next to the cache and named as the worst-case staleness.
  • The edit order: write the store, then purge the cache.
  • A disabled list checked on every request, including cache hits.
  • A note on why the redirect is a 302, not a 301.

APPLY IT

Sketch a URL shortener

GO DEEPER WITH OUR GUIDES

OFF-SITE SOURCES · NOT WRITTEN BY US

Sources and further reading

  • RFC 9111: HTTP Caching

    IETFrfcFree

    The rules for how HTTP caches decide freshness, expiry and reuse. Read the sections on freshness and on which status codes are cacheable by default.

  • HTTP caching

    MDN Web DocsdocsFree

    A readable guide to browser and shared caches, Cache-Control and why fresh vs stale matters.

  • Caching challenges and strategies

    Amazon Builders' LibraryarticleFree

    Lessons from running caches in production: cold starts, stale data, negative caching and what happens to the store when the cache disappears.

  • Purge cache

    Cloudflare DocsdocsFree

    A concrete example of explicit invalidation at an edge: purging by URL, tag or everything, and the limits that come with it.