What is a CDN (Content Delivery Network)?
Learn what a CDN is, how edge caching and cache misses work, and how CDNs cut latency and mitigate DDoS attacks.
Expected Interview Answer
A CDN (Content Delivery Network) is a geographically distributed network of proxy servers that cache and serve content from locations physically close to end users, reducing latency and origin server load compared to serving every request from a single central location.
When a user requests a page or asset, DNS or anycast routing directs them to the nearest CDN edge node rather than the origin server, and if that edge already has the content cached it serves it directly, dramatically cutting round-trip time. If the content is not cached, the edge node fetches it from the origin once, serves the user, and caches a copy for subsequent nearby requests, following patterns like cache-control headers and TTLs to decide how long to keep it. Beyond static assets, modern CDNs also absorb traffic spikes, provide DDoS mitigation by distributing and filtering attack traffic across many edge locations, and can run edge compute for lightweight logic close to the user. The tradeoff is cache invalidation complexity: purging or updating content across thousands of globally distributed edge nodes requires careful cache-control design to avoid serving stale data.
- Serves content from edge nodes near users, cutting latency
- Reduces load and bandwidth cost on the origin server
- Absorbs traffic spikes and helps mitigate DDoS attacks
- Enables edge compute for logic executed close to the user
AI Mentor Explanation
A CDN is like a cricket board setting up regional merchandise warehouses near each stadium instead of shipping every jersey from one central factory for every match-day order. A fan buying a jersey in their home city gets it from the nearby warehouse almost instantly, while the central factory only restocks each warehouse periodically. If a new design has not reached a regional warehouse yet, that one order is fulfilled directly from the factory and the warehouse restocks for next time. This is exactly how a CDN edge node serves cached content locally and falls back to the origin only when needed.
Step-by-Step Explanation
Step 1
Route to nearest edge
DNS or anycast routing directs the user’s request to the geographically closest CDN edge node.
Step 2
Check cache
The edge node checks whether it already has a valid cached copy of the requested content.
Step 3
Serve or fetch
A cache hit serves content immediately; a cache miss fetches it once from the origin server and caches it.
Step 4
Expire and revalidate
Cache-control headers and TTLs determine when cached content expires and must be revalidated or refreshed.
What Interviewer Expects
- Correct definition: distributed edge caching close to users
- Explains cache hit vs cache miss behavior and origin fetch
- Mentions cache-control/TTL and invalidation challenges
- Knows additional benefits: DDoS mitigation, traffic spike absorption, edge compute
Common Mistakes
- Thinking a CDN replaces the origin server entirely
- Not understanding cache invalidation is a real operational challenge
- Confusing a CDN with a simple load balancer
- Forgetting CDNs also serve dynamic content and edge compute, not just static files
Best Answer (HR Friendly)
“A CDN is a network of servers spread out around the world that store copies of a website’s content close to its visitors, so a user in Tokyo does not have to wait for data to travel from a server in Virginia. It makes websites load faster, handles traffic spikes better, and takes pressure off the original server, which is why almost every major website uses one.”
Code Example
# Check which edge server and cache status served a request
curl -sI https://example.com/logo.png | grep -Ei 'age|cache|x-cache|via'
# Typical CDN response headers:
# X-Cache: HIT
# Age: 3421
# Via: 1.1 varnish-edgeFollow-up Questions
- How does a CDN decide which edge node serves a given user?
- What is cache invalidation and why is it hard at CDN scale?
- How does a CDN help mitigate DDoS attacks?
- What is the difference between caching static assets and edge-computing dynamic logic?
MCQ Practice
1. What is the primary purpose of a CDN?
A CDN distributes cached content across edge servers close to end users to reduce latency and origin load.
2. What happens on a CDN cache miss?
On a cache miss, the edge node retrieves the content from the origin server once and stores it for future requests.
3. Besides speed, what is another key benefit CDNs provide?
CDNs distribute and filter traffic across many edge locations, helping absorb spikes and mitigate DDoS attacks.
Flash Cards
What is a CDN? — A distributed network of edge servers that cache and serve content near end users.
What happens on a cache hit? — The edge node serves the cached content immediately without contacting the origin.
What happens on a cache miss? — The edge fetches from the origin once, serves the user, and caches the result.
Name a non-speed CDN benefit. — DDoS mitigation by distributing and filtering attack traffic across edge nodes.