ayushsalampuriya.xyzRevise

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

Don't CDN: Personalized authenticated API responses unless carefully keyed and short-TTL.

3. Cache control headers

Cache-Control: public, max-age=31536000, immutable # hashed JS/CSS Cache-Control: public, max-age=3600 # product image Cache-Control: private, no-store # user dashboard

ETag / Last-Modified: Conditional requests — 304 Not Modified saves bandwidth.

4. Pull vs push CDN

5. Invalidation

When you deploy new JS bundle, old cached version is stale.

6. CDN + dynamic origin pattern

  1. Static assets → CDN → S3 origin
  2. API → LB → app servers (not CDN-cached)
  3. 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.