Web4 min read10 interview questions
What a CDN does
Why the same website loads fast in Chennai and in London.
In one sentenceA content delivery network keeps copies of your files in many cities so each visitor downloads from somewhere close.
Think of it like thisIt is like a book publisher stocking many local bookshops instead of making everyone order from one warehouse.
The big picture
Tap any step to see where to use it, how to use it and an example result.
Why distance matters
Data travels fast but not instantly. A round trip across the world adds noticeable delay for every file. Serving from nearby cuts that delay.
What it stores
Files that are the same for everyone: images, styles, scripts and often whole pages. Personal data, such as a logged-in dashboard, should not be stored for everyone.
Extra benefits
A CDN takes load off your server, absorbs sudden traffic spikes, and can block attacks before they reach you. Cloudflare, which hosts this site, is a CDN.
Common mistakes
- Caching personalised pages for everyone.
- Forgetting to refresh the cache after updating a file, so visitors see the old version.
- Using a different file name for each version only sometimes, so updates are unpredictable.
Quick recap
- A CDN keeps copies close to visitors
- Same-for-everyone files are cached
- Personal pages must not be shared
- Changing the file name or purging the cache shows updates
Try it yourself
Run a page speed test on any site you like and note which files come from a CDN.
Top 10 interview questions
Ordered from basic to advanced. Try answering out loud first, then open the answer.
What is a CDN?Basic
A content delivery network is a group of servers around the world that keep copies of your files and serve each visitor from a nearby location.
Why do websites use a CDN?Basic
To load faster for distant users, to reduce load on the main server, to absorb traffic spikes and to add protection against some attacks.
What kinds of content suit a CDN best?Basic
Files that are the same for many people: images, CSS, JavaScript, fonts, video and downloads. Personalised or fast-changing responses are harder to cache.
What is an origin server?Basic
The real server where your content lives. The CDN edge servers fetch from it when they do not already have a copy.
What is a cache hit and a cache miss at the edge?Intermediate
A hit means the edge already has the file and returns it immediately. A miss means it must fetch the file from the origin, return it and usually store it for next time.
How does a CDN know how long to keep a file?Intermediate
From cache headers sent by the origin, such as Cache-Control with max-age, plus rules set in the CDN. When the time ends the file is revalidated or fetched again.
How do you update a file that is already cached around the world?Intermediate
Either purge it in the CDN, or better, change its name when the content changes, for example app.3f9a.js. A new name is a new file, so no old copy can be served.
How does a visitor end up at the nearest CDN server?Intermediate
Usually through DNS that answers with a nearby edge, or through anycast, where many locations share one IP address and the network routes the visitor to the closest.
What can go wrong when caching dynamic or logged-in pages?Advanced
One user's private page might be cached and shown to another. Mark private responses Cache-Control: private or no-store, and make the cache key include everything that changes the response.
Besides speed, what else can a CDN provide?Advanced
TLS termination, DDoS absorption, a web application firewall, bot filtering, image resizing and running small pieces of code at the edge.
Guides are simplified on purpose. Tool names and details change, so check the official documentation before relying on a detail.