Content Delivery Network (CDN)
Globally distributed network of edge servers caching static files (JS, images, videos) closer to the user to bypass origin bottlenecks.
1. System Requirements
- Cache static and dynamic content at edge proxy locations.
- Resolve requests from the geographically closest Edge server via Anycast routing.
- Support compression (Gzip, Brotli) and cache invalidation APIs.
- Ultra-low latency connection handshakes (< 15ms).
- Scale to handle massive bandwidth spikes (Terabits per second).
2. Scale & Resource Estimates
Throughput: Millions of concurrent connections distributed across hundreds of global PoPs (Points of Presence).
Storage & RAM: Cached static files are stored on SSDs at edge servers. Size scales with media libraries.
3. System API Endpoints
// Origin Request Resolution
HTTP GET /assets/hero.jpg
DNS resolves to closest Edge PoP IP
If (Edge Cache Hit) -> Return assets
If (Edge Cache Miss) -> Fetch from Origin server, Cache, Return
4. Database Schema Design
Cache-Control Headers:
Cache-Control: public, max-age=31536000, immutable
ETag: "W/df382-990a424"
5. Interactive High-Level Architecture
6. Scalability Deep Dive & Bottlenecks
CDNs use Anycast routing to advertise a single IP address from multiple global locations. When a user requests a file, BGP routing routes the packets to the closest physical Point of Presence (PoP). CDNs utilize Cache-Control headers (like s-maxage) to define expiration times. For dynamic caching, CDNs evaluate caching rules at the edge to compress and minify content.
7. Production Scaling Strategies
Brotli Compression: Reducing asset transfer sizes by up to 25% compared to gzip to speed up edge downloads.
Origin Shielding: Positioning a dedicated high-capacity proxy layer in front of the origin servers to protect them from cache misses.
Invalidation Webhooks: Releasing instant purge requests to globally invalidate files in < 150ms.
8. Runnable Production Starter Code
Scaffold