Beating the Speed of Light
Network packets are physically bound by the speed of light across fiber optic cables. If your server sits in a data center in Virginia and a user connects from a café in Mumbai, their request physically crosses undersea cables beneath the Atlantic and Indian Oceans. This creates an unavoidable ~200ms round-trip penalty.
A modern webpage loads 50+ assets (images, scripts, fonts). Without optimization, that Mumbai user stares at a blank screen for 3-4 seconds. A CDN (Content Delivery Network) solves this constraint of physics.
Real-World Example: Netflix
Netflix serves over 15% of all internet bandwidth globally. They built their own CDN called Open Connect—custom hardware appliances placed directly inside ISP data centers in 1,000+ locations worldwide. When you stream a movie, you''re literally downloading from a server in your ISP''s own building, not from Netflix''s AWS origin. This is why Netflix can deliver 4K video with barely any buffering, even during peak evening hours.
How CDNs Work: Edge Servers
A CDN is a globally distributed network of proxy servers called "Edge Nodes." Providers like Cloudflare (300+ cities), AWS CloudFront (400+ edge locations), and Akamai (4,000+ edge servers) maintain physical presence worldwide.
When a user in Tokyo requests your website''s logo, their DNS query is transparently routed to the nearest edge node—right there in Tokyo. The latency drops from 200ms to 5ms.
[!NOTE] CDNs primarily cache static assets: JavaScript bundles, CSS stylesheets, images, fonts, and video files. You cannot easily cache live, dynamic data (like a user''s shopping cart) at the edge. But static assets often account for 80-90% of bandwidth, so this alone massively offloads your origin server.
Push vs Pull CDNs
Push CDN
You manually upload assets to the CDN, which proactively distributes them to all global nodes. You''re responsible for pushing updates when files change.
- Best for: Large, rarely changing libraries of static files (e.g., Apple''s App Store assets, game downloads).
- Example: Apple pre-pushes iOS updates to CDN nodes worldwide before the public release date. When 100 million iPhones hit "Download" simultaneously, the traffic is already distributed.
Pull CDN
Assets live on your origin server. When a user first requests logo.png, the nearest edge node fetches it from the origin ("Cache Miss"), caches it locally, and serves all subsequent requests from cache ("Cache Hit").
- Best for: Sites with high traffic and frequently updating assets (e.g., news sites, blogs, SaaS products).
- Example: The New York Times uses a pull CDN—when a breaking news story goes viral, CloudFront caches the article and images at hundreds of edge locations within seconds.
Cache Invalidation: The Hard Problem
There''s a famous saying in computer science: "There are only two hard things in CS: cache invalidation and naming things." With CDNs, this problem is real:
- Fingerprinted filenames: The safest approach. Name your files with a content hash (e.g.,
app.3f2a1b.js). When the file changes, the hash changes, so the CDN treats it as a brand new file. No stale cache risk. - Cache-Control headers: Set
max-ageands-maxageto control how long edge nodes cache each asset. - Purge APIs: Most CDNs let you manually purge specific URLs or entire paths when needed (e.g., after a critical hotfix).
Beyond Static: Edge Computing
Modern CDNs are evolving beyond static caching. Cloudflare Workers, AWS Lambda@Edge, and Vercel Edge Functions let you run server-side code at the edge—executing authentication, A/B testing, or personalization logic in the edge node closest to the user. This blurs the line between "CDN" and "distributed compute platform."
[!TIP] Interview tip: When designing any read-heavy system, mention CDNs early. A CDN is often the first thing you deploy to improve user experience globally. Even if your origin server is in one region, a CDN gives you global performance for pennies per GB.