Skip to the page

Cross-cutting concerns (the O in RADIO) · senior

Caching layers from CDN to component

Describe caching as layers: CDN, browser HTTP cache, service worker, in-memory query cache and IndexedDB. For each one, say what is cached, for how long, and how it is invalidated.

The notes

What you must know

  • Hashed static assets: Cache-Control: public, max-age=31536000, immutable. HTML: short max-age or no-cache with ETag revalidation.
  • CDN: cache public pages and public API responses (s-maxage, stale-while-revalidate); personalised responses must be private or keyed correctly, or users see each other's data.
  • The browser HTTP cache follows headers. The Cache API used by service workers is separate and ignores Cache-Control: your code decides.
  • Service worker strategies: cache-first for versioned assets; network-first for HTML/API that must be fresh but work offline; stale-while-revalidate for avatars and non-critical data; network-only; cache-only for precached files.
  • In-memory query cache: key = endpoint + params; staleTime (when to refetch) vs gcTime (when to drop); dedupe in-flight requests; invalidate by key or tag after mutations.
  • IndexedDB or OPFS for large or offline data. Notion runs WASM SQLite in OPFS through one 'active tab' worker; page navigation got 20% faster overall and 33% faster in India.
  • Invalidation is the hard part: versioned URLs, tags (Next.js cacheTag/updateTag), ETags, push events; bound memory with LRU limits.

The red pen

Common traps: mistake → fix

  • Mistake: Cache-Control controls what the service worker caches

    Fix: the Cache API is separate.

  • Mistake: Cache everything for a long time

    Fix: stale prices, stale stock and cross-user leaks.

  • Mistake: localStorage is a good API cache

    Fix: it is synchronous, small (about 5 MB), strings only, and blocks the main thread.

  • Mistake: Caching failed responses saves calls

    Fix: don't cache errors or rejected promises.

Easy to hard

Questions interviewers ask, easy to hard

  1. What Cache-Control would you set for JS bundles and for HTML?
  2. Walk through all the caches between the user and the database for a product page.
  3. Which service worker strategy for: app shell, product API, user avatars?
  4. After a price update, how does every cache layer learn about it?

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview