CDN
A CDN (Content Delivery Network) is a group of servers in different locations that can deliver website files and other content from a server closer to the user, speeding up delivery and reducing traffic to the original server.
Also known as: Content Delivery Network
Why put a CDN in front of a site?
Imagine your app is hosted in Virginia and a customer in Sydney opens it. Without a CDN, the customer's browser may have to fetch every image, font, and script from Virginia. With a CDN, it can get cached copies from a server in Australia. That server is called an edge server; the web server or storage service that supplies the original content is called the origin.
Follow a request
DNS, network routing, or a combination of the two directs the browser to an edge location. The selected location is not necessarily the closest on a map. The edge acts as a reverse proxy: it receives the request and checks its cache for a matching response. The cache key typically includes the host and path. Depending on the configuration, it may also include query parameters or selected request headers.
On a cache hit, the edge serves a fresh stored response without contacting the origin. On a cache miss, it fetches the response from the origin or an upstream cache and stores it if the caching policy allows. A time to live (TTL) determines how long a stored response is considered fresh. Once it goes stale, the CDN can fetch a replacement or ask the origin whether the response has changed. With an ETag, for example, the origin can return 304 Not Modified rather than resending the response body.
Example: shipping a new stylesheet
Suppose a build produces site.a91c.css. Because the filename contains a content hash, changing the stylesheet produces a new URL. The origin can serve the file with Cache-Control: public, max-age=31536000, immutable. Browsers and shared caches can then reuse it for a long time without confusing it with a newer version. Give the HTML a shorter TTL or require revalidation: otherwise users may still get an old page that points to the old stylesheet.
Common mistakes
A CDN can proxy requests without caching them. That's often what you want for account pages and personalized API responses: shared caches must not serve one user's private data to another. For public content, check which inputs actually change the response. A campaign-tracking parameter can usually be left out of the cache key if it has no effect on the response, but a parameter that selects an image size belongs in the key.
Purging a CDN cache is useful when you need to replace content at the same URL, but a purge may take time to reach all locations and does not clear browser caches. Also, a warm cache in one location does not guarantee a hit in another.
What interviewers look for
Be ready to troubleshoot a drop in cache hit ratio rather than just define it. Check the affected paths and edge locations, inspect Cache-Control and the CDN's cache-status header if available, and look for recent changes to TTLs, cache keys, or asset URLs. Compare the hit ratio with origin request volume and user-facing latency to see whether the drop actually hurt performance.