Designing Content Delivery Networks
1. Designing CDN Architecture
Client ─▶ Edge PoP (cache) ─▶ Regional Cache ─▶ Origin Shield ─▶ Origin
| Layer | Detail |
|---|---|
| Edge PoP | Closest to user; first cache |
| Mid-tier | Reduces origin requests |
| Origin shield | Single egress to origin |
| Anycast routing | BGP routes to nearest PoP |
2. Designing Edge Caching Strategy
| Aspect | Detail |
|---|---|
| Cache key | URL + query (selective) + headers (Vary) |
| TTL | Long for static; short for HTML |
| Stale-while-revalidate | Serve stale, refresh async |
| Cache hit ratio target | >90% for static |
3. Designing Cache-Control Headers
| Directive | Use |
|---|---|
| public / private | Shared vs browser-only |
| max-age=N | Browser TTL |
| s-maxage=N | CDN TTL (overrides max-age for shared) |
| stale-while-revalidate | Background refresh |
| immutable | For hashed assets |
| no-store | Sensitive data |
4. Designing Static Asset Delivery
| Practice | Detail |
|---|---|
| Hashed filenames | app.a1b2.js → infinite cache |
| Compression | brotli > gzip; precompute |
| HTTP/2 / HTTP/3 | Multiplexing, QUIC |
| Image formats | AVIF, WebP fallback |
| Preload / prefetch | Critical assets |
5. Designing Dynamic Content Acceleration
| Mechanism | Detail |
|---|---|
| TLS termination at edge | Reduce handshake RTT |
| Persistent origin connections | Reuse keep-alive |
| Edge compute | Cloudflare Workers, Lambda@Edge |
| Micro-cache | Cache dynamic for 1–5s |
| Optimal route | Private backbone (e.g., Cloudfront, Akamai) |
6. Designing API Acceleration
| Technique | Detail |
|---|---|
| CDN as API gateway | Auth + cache + rate limit at edge |
| Cache GET responses | With ETag |
| Edge auth | JWT verify at PoP |
| Origin shield | Reduce backend load |
7. Designing Geographic Routing
| Strategy | Detail |
|---|---|
| Latency-based | Route to fastest origin |
| Geo | By country / region |
| Compliance | EU users → EU origin (GDPR) |
| Failover | Health-based |
8. Designing CDN Purging and Invalidation
| Method | Detail |
|---|---|
| URL purge | Specific path |
| Tag-based purge | Surrogate-Key header (Fastly) |
| Version in URL | Deploy busts cache |
| Soft purge | Mark stale; revalidate |
9. Designing CDN Security
| Feature | Detail |
|---|---|
| WAF | OWASP rules at edge |
| DDoS shield | L3/4 + L7 |
| Bot management | Fingerprint + JS challenge |
| Hotlink protection | Referer / signed URLs |
| Origin lockdown | Allow-list CDN IPs only |
10. Designing CDN Performance Optimization
| Lever | Detail |
|---|---|
| Brotli precompression | Stored at edge |
| Image resize at edge | Per device |
| HTTP/3 (QUIC) | Better mobile / lossy |
| 0-RTT resumption | TLS 1.3 session tickets |
| Tiered caching | Lower origin load |
11. Designing Multi-CDN Strategy
| Aspect | Detail |
|---|---|
| Vendor diversity | Avoid single-vendor outages |
| Routing | RUM / DNS-based steering (NS1, Cedexis) |
| Cost arbitrage | Per-region pricing |
| Operational cost | Cert mgmt, config sync |
12. Designing Origin Shielding
| Aspect | Detail |
|---|---|
| Concept | Single intermediate cache fronts origin |
| Benefit | Higher hit ratio at origin shield; less origin load |
| Placement | Region near origin |
| Caveat | Single cache layer hot-key risk |