,

Contents · CDN architectures and caching


Why CDNs? Latency, offload, availability

  • Reduce latency via proximity; offload origin bandwidth and compute.
  • Improve resilience with regional isolation and multi-origin failover.
  • Lower egress costs with edge caching and peering.

Topology: POPs, edges, mid-tier, origins

  • Hierarchical caches: edge → regional/mid-tier → origin shield → origin.
  • Anycast to nearest POP; DNS steering for geo/latency-aware routing.
  • Active-active origins and shield layers reduce origin amplification.

Caching: keys, TTL, validation

  • Cache key components: host, path, query, headers (Vary), device hints.
  • Freshness: Cache-Control (max-age, s-maxage), Expires; revalidation via ETag/If-None-Match.
  • Edge compute can rewrite keys and responses (workers/functions).
Cache-Control: public, max-age=600, s-maxage=3600

Invalidation, versioning, and cache busting

  • Invalidate by URL/prefix, or version assets with content hashes for instant rollover.
  • Stale-while-revalidate and stale-if-error improve resilience.
  • Blue/green asset switch via manifest or immutable paths.

Request routing: DNS, anycast, Geo/IP, ECMP

  • Geo DNS maps client resolvers to nearby POPs; anycast BGP announces the same prefix globally.
  • Latency-based routing and health checks steer traffic away from faults.
  • Per-request redirects based on device/geo via edge logic.

Security: TLS, WAF, DDoS, bot mitigation

  • Edge TLS termination with modern ciphers; HSTS and OCSP stapling.
  • WAF rules for OWASP Top 10; rate limiting; bot scoring and challenges.
  • Automatic DDoS mitigation with scrubbing and anomaly detection.

HTTP/2, HTTP/3, compression, image optimization

  • Enable Brotli/gzip; optimize images (WebP/AVIF) and responsive variants.
  • Coalesce connections with H/2; migrate to H/3 for better loss resilience.
  • Use signed exchanges, preconnect, and early hints where supported.

Operations and observability

  • Metrics: hit ratio, origin offload, TTFB by POP, error rates, invalidation latency.
  • Logs/traces at edge and origin; correlate with synthetic monitoring.
  • Plan capacity per POP; simulate regional failures; test cache warm strategies.

Exercises

  1. Design a CDN for a global video site: pick POP regions, caching rules, and routing.
  2. Implement cache-busting with content hashes and verify fast rollbacks.
  3. Measure hit ratio improvements after adding an origin shield layer.
CDNs let you move compute and cache closer to users—use them to deliver faster and more resilient experiences.