Quick reference · Print-friendly

Cache correctness field guide

For every value: audience, key, staleness, invalidation, failure.

5 checksBefore choosing a TTL

Policy worksheet

QuestionExamplesFailure if omitted
What is cached?HTML, RSC payload, JSON, query result, assetYou purge one representation while another stays stale.
Who may share it?Everyone, region, tenant, one user, one browserPersonalization or authorization leaks across audiences.
What forms the key?Path, query, locale, region, tenant, content versionDistinct variants collide or cardinality destroys hit rate.
How stale may it be?Immutable, hours, seconds, never for decisionsThe infrastructure silently chooses product semantics.
How does it leave?TTL, validator, tag, purge, versioned URLUpdates fail to propagate or create origin spikes.

HTTP directive decoder

DirectiveMeaningCommon mistake
max-age=NFreshness lifetime for caches, including private cachesAssuming it guarantees origin-current data
s-maxage=NFreshness lifetime for shared caches; overrides max-age thereForgetting the browser and CDN now have different policies
privateMay be stored only by a private cacheTreating it as equivalent to no storage
no-cacheMay store; must validate before reuseReading the name as “do not cache”
no-storeDo not store this responseAdding it everywhere and losing useful browser behavior
stale-while-revalidate=NMay serve stale for N seconds while validating asynchronouslyIgnoring how many stale versions users may observe
stale-if-error=NMay serve stale for N seconds when origin failsUsing it for data where stale is less safe than unavailable
immutableRepresentation will not change during freshness lifetimeUsing it on URLs whose contents can change

Interview decision sequence

  1. Split the page into data classes instead of assigning one route-wide freshness label.
  2. State the accepted staleness and consistency requirement for each class.
  3. Select the sharing audience and enumerate every key dimension.
  4. Choose TTL, event invalidation, conditional validation, or versioned URLs.
  5. Keep permissions, money, quotas, and inventory authoritative at mutation time.
  6. Trace invalidation through browser, CDN, application, and data caches.
  7. Plan stampede control, stale-on-error policy, and a bounded expiry backstop.
  8. Observe hit ratio, Age/Cache-Status, purge lag, stale responses, and origin load.

Follow-up prompts to expect

“What is the cache key?”

Name every representation-changing input and explain how you avoid unsafe collisions and uncontrolled cardinality.

“What if invalidation is lost?”

Use reliable events plus a bounded TTL backstop, observability, and manual purge capability.

“What happens during a spike?”

Discuss request coalescing, early refresh, jitter, bounded stale serving, and origin protection.

“How do writes appear immediately?”

Use write-through/update or targeted expiry for read-your-own-writes rather than background SWR.