advanced

CDN cache

Cache public edge responses using cache-control, surrogate keys, purge strategy, and stale response rules.

CDNs cache static assets and cacheable API responses at edge PoPs close to users. Control freshness with Cache-Control, ETag, surrogate keys, and signed URLs for private content. Purge by URL or surrogate key when origin content changes.

Use CDNs for images, videos, JS bundles, and public read-heavy APIs. Dynamic personalized responses usually bypass cache or use short TTLs with Vary headers.

On interviews: explain cache-control for a product image, purge strategy after deploy, and stale-while-revalidate for resilience.

Common pitfalls: caching authenticated responses without Vary; long TTL on HTML breaking releases; no purge automation after CMS updates.

The trade-off is flexibility versus complexity—know when the simpler path is enough.

Checklist:

  • Set cache-control per content type.
  • Define purge triggers on publish/deploy.
  • Use surrogate keys for bulk invalidation.
  • Plan stale serving during origin outages.