Why CDNs? Latency, offload, availability
Motivation | 6-minute read
- 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
Architecture | 8-minute read
- 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
HTTP caching | 9-minute read
- 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
Freshness | 7-minute read
- 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.
Security: TLS, WAF, DDoS, bot mitigation
Protection | 7-minute read
- 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
Performance | 8-minute read
- 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.
Exercises
Hands-on | 8-minute read
- Design a CDN for a global video site: pick POP regions, caching rules, and routing.
- Implement cache-busting with content hashes and verify fast rollbacks.
- 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.