HLD · Edge
CDN & Content Delivery
Serve static and cacheable content from edge locations close to users.
1. What is a CDN?
A Content Delivery Network is a geographically distributed set of edge servers (PoPs) that cache content from an origin server.
Example: User in Mumbai requests cdn.site.com/logo.png → served from Mumbai PoP (20ms) instead of US origin (300ms).
2. What belongs on a CDN
- Images, videos, CSS, JS bundles
- Static HTML (marketing pages)
- Cacheable API responses (public product catalog) with correct headers
Don't CDN: Personalized authenticated API responses unless carefully keyed and short-TTL.
3. Cache control headers
ETag / Last-Modified: Conditional requests — 304 Not Modified saves bandwidth.
4. Pull vs push CDN
- Pull (most common): CDN fetches from origin on first request, then caches. Origin = S3, your web server.
- Push: You upload content to CDN proactively. Live streaming, large file distribution.
5. Invalidation
When you deploy new JS bundle, old cached version is stale.
- Cache busting: Filename hashing —
app.a1b2c3.js(best practice) - Purge API: Cloudflare/Fastly purge by URL or tag — use sparingly (propagation delay)
6. CDN + dynamic origin pattern
- Static assets → CDN → S3 origin
- API → LB → app servers (not CDN-cached)
- Hybrid: CDN caches GET /api/v1/products with 60s TTL at edge
7. DDoS and TLS
CDNs absorb volumetric attacks at edge. TLS often terminates at CDN; origin can use private network or mTLS.
8. Example: video streaming (YouTube-like)
Upload → origin storage → transcoding → segments to CDN. Playback requests HLS chunks from nearest PoP. Popular videos stay hot in cache.
9. Providers
Cloudflare, Akamai, Fastly, AWS CloudFront, Google Cloud CDN.
Quick revision
- CDN: Edge cache → lower latency, less origin load.
- Cache-Control drives CDN behavior; hash filenames for busting.
- Pull CDN on cache miss fetches origin once.
- Static on CDN; personalized APIs usually bypass or short TTL.
- Bonus: DDoS absorption + TLS at edge.