A Content Delivery Network (CDN) is a distributed network of edge servers that cache and serve content to users based on geographic proximity, reducing latency and origin server load.

The Edge Caching Model

When a user requests a resource, the CDN intercepts the request at the nearest Point of Presence (PoP).

  1. Cache Hit: Resource is served from the PoP with sub-$20\text$ latency.
  2. Cache Miss: PoP fetches from the Origin, caches it, and then serves the user.

Cache-Control Strategy

The CDN behavior is governed by HTTP response headers from the origin.

Header ValueEffectUse Case
public, max-age=31536000, immutableCache forever (1yr). Never revalidate.Versioned assets (JS/CSS).
public, s-maxage=3600, max-age=60Cache at Edge for 1hr, Browser for 1min.Public API data.
no-store, privateNever cache. Pass through to origin.Personalized dashboards.

Origin Shielding

Origin Shield is an intermediate caching layer between PoPs and the primary origin.

Cache Invalidation Patterns

  1. TTL (Time-To-Live): Automatic expiration. Low complexity, but introduces staleness.
  2. Purge by URL: Explicitly mark a resource as stale via API. High latency ($5\text+$ propagation).
  3. Cache-Busting (Recommended): Fingerprint URLs with content hashes (e.g., app.v1.2.js \rightarrow app.v1.3.js). Eliminates the need for manual invalidation.

Edge Compute

Modern CDNs (Cloudflare Workers, Lambda@Edge) allow execution of code at the PoP.

Security at the Edge

Operational Checklist