CDN
A network of servers around the world that deliver content from the location closest to each user.
What is it?
The further data has to travel over the internet, the longer it takes to arrive. If your only server is in one country, users on the other side of the world will always experience a noticeable delay. A CDN (Content Delivery Network) solves this by storing copies of your content — images, videos, scripts, static files — on servers spread across many locations worldwide, and serving each user from whichever copy is physically closest to them.
Explain like I'm 10
It's like a chain of grocery stores instead of one giant warehouse. Rather than everyone driving across the country to the single warehouse, each town has a local store stocked with the same goods, so everyone gets what they need quickly.
Examples
Conceptual CDN request flow
// Without a CDN:
// User in Tokyo → server in New York → slow round trip
// With a CDN:
// User in Tokyo → nearby CDN server in Tokyo (already has a copy) → fastHow it works
When content is published, it's copied ("cached") across many CDN servers ("edge locations") around the world. When a user requests that content, they're automatically routed to the nearest edge location, which serves the cached copy directly — without needing to contact the original server at all, unless the content is missing or has expired there.
Why does it exist?
CDNs dramatically reduce load times for users far from the origin server, and also reduce load on that origin server, since most requests are served from edge locations instead. They're especially valuable for content that doesn't change often, like images, videos, and static files.
When to use it
Reach for a CDN when you're serving static assets — images, videos, JS/CSS bundles — to users spread across different geographic regions, and you want those assets to load quickly no matter where the user is.
When not to use it
Don't rely on a CDN for highly personalized or constantly-changing data — that's not what it's built to cache well. And if your entire user base is already geographically close to your one server, a CDN's main benefit (proximity) doesn't buy you much.
Common mistakes
Using a CDN for highly personalized, frequently-changing data that isn't a good fit for caching.
Forgetting to invalidate CDN caches after updating content, so users keep seeing an old version.
Assuming a CDN replaces the need for a fast origin server — it helps most with static content, not every kind of request.
Practice exercises
- Easy:
Explain, in your own words, why a user in a different country might experience a slow-loading website without a CDN.
- Medium:
List which parts of a typical website (images, live account data, CSS files) are a good fit for a CDN, and which aren't.
- Hard:
Describe what could go wrong if you don't properly invalidate a CDN cache after deploying a new version of your website's images.
Interview questions
What problem does a CDN solve?
It reduces the distance content has to travel by serving it from a location physically closer to each user, lowering latency and reducing load on the origin server.
What kind of content is best suited for a CDN?
Static, rarely-changing content like images, videos, stylesheets, and scripts — not highly personalized or constantly-changing data.
What is an 'edge location'?
One of many CDN servers distributed geographically, each holding cached copies of content to serve nearby users quickly.