Content Delivery Networks

A Content Delivery Network (CDN) distributes cacheable content across geographically dispersed edge servers so users can retrieve resources from a nearby location. This reduces latency, lowers traffic to the origin server, and improves scalability for web applications.

A CDN is a network of edge servers positioned in multiple geographic regions. Instead of every request reaching the origin server, requests for cacheable assets such as images, JavaScript, CSS, fonts, and videos are often served from the closest edge location. This shortens the network path and typically improves page load times.

When a client requests a resource, DNS or another routing mechanism directs the request to a suitable edge server. If the requested object is already cached there, the edge immediately returns it. Otherwise, the edge fetches the object from the origin, stores it according to caching rules, and serves it to the client.

Caching behavior depends on policies such as `Cache-Control`, `Expires`, and entity validation headers like `ETag`. Correct cache configuration balances freshness with performance. Frequently changing resources may use shorter cache durations or versioned file names to ensure users receive updated content.

For frontend engineers, a CDN primarily improves delivery of static assets and media. It can also reduce bandwidth usage and request volume at the origin, making applications more resilient during traffic spikes. Dynamic or personalized responses are generally less cacheable, although some CDNs support selective caching and edge-side logic.

Key points

Interview questions

What problem does a CDN solve?

A CDN reduces the distance between users and static content by serving cached resources from nearby edge locations. This lowers latency and decreases page load times. It also reduces traffic reaching the origin server, improving scalability and resilience. The biggest benefits are usually seen for static assets and media.

What is a cache hit versus a cache miss?

A cache hit occurs when the requested object already exists on an edge server and can be returned immediately. A cache miss means the object is unavailable at the edge, so the CDN retrieves it from the origin before serving and potentially storing it. High cache hit rates usually improve performance and reduce origin load.

How do HTTP caching headers affect CDN behavior?

Caching headers communicate whether a response may be stored and for how long. A CDN uses directives such as `Cache-Control` and `Expires` to determine cache lifetime, while validators like `ETag` help verify freshness. Correct header configuration improves performance without serving outdated content.

Why are versioned asset filenames commonly used with CDNs?

Versioned filenames allow static assets to be cached for long periods while ensuring updates are fetched as new resources. When content changes, the filename changes as well, avoiding stale caches without relying on immediate invalidation. This approach is common in modern frontend build pipelines.

When might a CDN provide limited performance benefits?

Applications dominated by personalized or rapidly changing responses may see fewer caching benefits because many responses cannot be shared across users. In those situations, network optimization still helps, but cache efficiency is lower. Engineers should identify which content is cacheable and separate static assets from dynamic responses whenever possible.