CDN and Edge Computing Explained: Serving Content From the Nearest Location
How CDNs and edge computing work — caching layers, cache invalidation, edge functions, and designing systems that leverage geographic distribution.
CDN and Edge Computing
A Content Delivery Network (CDN) is a geographically distributed network of servers that caches and serves content from locations close to users, reducing latency and offloading traffic from origin servers. Edge computing extends this by running application logic at these edge locations.
What It Really Means
Physics imposes a hard limit on network performance: the speed of light. A request from Tokyo to a server in Virginia takes at least 80ms for the round trip through fiber optic cables. No amount of server optimization can change this. The only solution is to move the content closer to the user.
A CDN does exactly this. Instead of every user worldwide hitting your origin server in Virginia, CDN edge servers in Tokyo, London, Sao Paulo, and 200+ other locations cache your content and serve it locally. A user in Tokyo gets a response in 5ms from the nearest edge server instead of 80ms from Virginia.
Edge computing goes further: instead of just caching static content, you run application logic at the edge. Cloudflare Workers, AWS Lambda@Edge, and Deno Deploy execute your code in data centers worldwide, enabling personalization, authentication, and API responses at edge speeds.
How It Works in Practice
CDN Request Flow
Cache Control Headers
Cache Invalidation Strategies
Implementation
Edge function (Cloudflare Worker):
CDN configuration for an API:
Trade-offs
CDN benefits:
- Reduced latency (serve from nearest edge)
- Origin offload (CDN handles 90%+ of requests)
- DDoS protection (absorb traffic at the edge)
- Automatic SSL termination
CDN challenges:
- Cache invalidation complexity ("the two hard things in CS")
- Cache stampede: When cached content expires, all edge servers simultaneously request the origin
- Debugging: Cached responses can mask origin bugs
- Cost: CDN bandwidth is not free, especially for video
Edge computing benefits:
- Sub-10ms response times for dynamic content
- Personalization without origin round-trips
- Reduced origin server load
- Geographic compliance (process EU data in EU)
Edge computing limitations:
- Limited compute resources per request (CPU time limits)
- No persistent connections to databases (use edge-compatible databases)
- Cold start latency (less than serverless but still exists)
- Debugging distributed edge functions is complex
Common Misconceptions
- "CDNs are only for static content" — Modern CDNs cache API responses, dynamic HTML, and even GraphQL queries. The key is correct Cache-Control headers.
- "Cache invalidation is instant" — Purge propagation across 200+ edge locations takes seconds to minutes. Design for eventual consistency in your caching strategy.
- "More caching is always better" — Caching user-specific data at the CDN can expose private data to other users. Always use
Cache-Control: privatefor personalized content. - "Edge computing replaces your backend" — Edge functions are ideal for request routing, authentication, and personalization. Complex business logic and database transactions belong at the origin.
- "A CDN eliminates the need for server-side optimization" — Cache misses still hit your origin. If your origin is slow, the first request to each edge location will be slow.
How This Appears in Interviews
- "Design a system to serve images to millions of users" — CDN with geographic distribution, cache headers, image optimization at the edge.
- "How do you handle cache invalidation for product prices?" — Short TTL for price data, cache busting for product images, purge API for urgent updates.
- "Design a global low-latency API" — Edge functions for read-heavy endpoints, CDN caching for semi-static data, regional databases for writes.
- "How do you protect against DDoS attacks?" — CDN absorbs traffic at the edge, rate limiting at edge locations, origin shielding.
Related Concepts
- DNS Resolution — CDNs use DNS for geographic routing
- CORS — CDN responses must include correct CORS headers
- HTTP/2 Multiplexing — CDN connections use HTTP/2
- Tail Latency — CDN cache misses affect p99 latency
- Blue-Green vs Canary Deployments — edge deployments use canary patterns
- System Design Interview Guide
- Algoroq Pricing — access all concept deep-dives
GO DEEPER
Learn from senior engineers in our 12-week cohort
Our Advanced System Design cohort covers this and 11 other deep-dive topics with live sessions, assignments, and expert feedback.