CDN & Edge Computing
Serve static media, video segments, and dynamic edge logic milliseconds from the user.
In plain words
A CDN keeps copies of your files (images, videos, scripts) on servers all over the world, so users download them from somewhere close instead of from your one main server.
Think of it like…
Local neighborhood convenience stores stocked from one central warehouse so shoppers do not drive 500 miles for milk.
Where you’ve seen it
A YouTube video is cached on a server in your city. When you press play it loads quickly, and the main data center never sees your request.
Words you’ll hear
- CDN
- Content delivery network: a worldwide set of servers that cache your content.
- Edge / PoP
- A point of presence: a CDN server location near users.
- Origin
- Your own main server, where the original files live.
- Cache hit ratio
- The share of requests served from the CDN without going to the origin.
Visual diagram
Theory & deep dive
How a CDN speeds up the web and protects your servers
A Content Delivery Network (CDN) places hundreds of edge servers (Points of Presence, or PoPs) in cities worldwide. Instead of 10 million users downloading a 5 MB video from one origin server in Virginia, they download it from a PoP a few miles from their home.
This gives two huge wins at once: lower latency for users (~15 ms instead of ~150 ms) and 90–99% lower origin load and bandwidth bills.
Pull CDN vs. Push CDN & Cache Invalidation
In a Pull CDN, the edge fetches files from your origin the first time a user requests them and caches them based on Cache-Control: max-age=86400. This is effortless and standard for most websites.
In a Push CDN, you upload files straight to the CDN ahead of time - useful for massive software releases or scheduled video drops. To update cached files early without slow global purges, use versioned URLs like /app.a8f3c1.js with max-age=31536000, immutable.
How it works, step by step
Step 1 of 41. User requests asset from nearest Edge PoP
Anycast or GeoDNS lands the user on an edge server <20 ms away. TLS terminates locally at the PoP.
- Edge Cache Hit
- 85–98%
- TLS RTT
- Local PoP
When to use it & trade-offs
What it is
A Content Delivery Network (CDN) is a globally distributed network of edge servers (PoPs) that cache and serve content near users, shielding origin servers from repetitive bandwidth.
Why it matters: Fetching 5 MB images or 4K video chunks across continents burns origin bandwidth and adds 150+ ms of RTT; CDNs absorb 90%+ of that traffic at the edge.
When to reach for it
- Images, HLS/DASH video chunks, fonts, JS/CSS bundles, and public downloads
- Absorbing viral traffic spikes and DDoS volumetric attacks
- Caching public API responses with
Varyandstale-while-revalidate
When to avoid or be careful
- Caching private user-specific responses on a shared URL without auth/Vary separation
- Triggering expensive wildcard purges on every deploy instead of hashed asset filenames
Push CDN vs. Pull CDN
Strengths: Zero upload orchestration; edge fetches on first miss and caches by HTTP headers.
Watch out: First request per PoP incurs a cache-miss round trip to origin.
Strengths: Zero cold-start misses; full control over what stays on edge disks.
Watch out: Higher storage cost and manual upload/deletion pipelines.
Strengths: Runs near user before hitting origin; avoids origin round trips for simple logic.
Watch out: Tight CPU/memory limits and no direct connection to central SQL databases.
Interview signals & numbers to know
When this topic comes up
- video streaming
- photo sharing
- global users
- static assets
- reduce egress cost
Benchmarks & rules of thumb
- Edge PoP RTT
- 10–30 ms
- Origin Shield hit boost
- 5–20× fewer origin misses
- Global cache purge time
- ~1–5 seconds
- Bandwidth savings
- 70–95% off origin
Common mistakes & follow-ups
Common interview mistakes
- Caching authenticated responses without
Cache-Control: private(leaking user A’s data to user B) - Skipping Origin Shield when 100+ PoPs miss simultaneously on a newly published viral video
- Setting
Vary: User-AgentorVary: Cookieon static assets, destroying the cache hit ratio
Likely interviewer follow-ups
- How does an Origin Shield prevent a thundering herd on your S3/origin tier?
- When would you use content-hashed URLs vs. an active CDN purge API?
- How do you serve private paid media (e.g., course videos) through a public CDN?
Knowledge check
Put it into practice
Design full architectures with AI feedback
Apply CDN & Edge Computing inside real High-Level Design prompts or review Q&A flashcards.