Frontend System Design · Lesson 27 of 86 · 4 min
CDN Benefits: Latency, Availability, Offload
In a system design interview, you justify using a CDN with these three specific benefits. Know them cold.
When you propose using a CDN, you're not just adding a box to a diagram. You are making a specific engineering trade-off to improve performance and reliability. You need to articulate precisely what you gain. The three core benefits are lower latency, higher availability, and reduced load on your origin server.
Reduce Latency by Serving Closer to the User
The speed of light is a hard limit. The farther your user is from your server, the higher the latency. A CDN shortens this distance by caching your assets on servers (Points of Presence, or PoPs) around the world.
When a user in Sydney requests a JavaScript bundle from your origin server in Virginia, the request has to cross the Pacific and back. The round-trip time (RTT) alone could be 150-200ms. If that asset is instead served from a CDN PoP in Sydney, the RTT drops to under 20ms.
This has a direct, measurable impact on Core Web Vitals. Lower latency for critical CSS and JavaScript files improves First Contentful Paint (FCP) and Largest Contentful Paint (LCP). Faster asset loading means your app becomes interactive sooner.
In an interview, don't just say "it makes the site faster." Say: "By placing assets on edge servers closer to the user, we reduce network RTT. This directly improves our LCP and FCP metrics, especially for our global user base."
Increase Availability Through Redundancy
A CDN is a massively distributed system. This inherent redundancy makes your application more resilient.
If a single CDN edge server fails, traffic is automatically rerouted to the next nearest healthy one. The user might experience a slightly higher latency for one or two requests, but the site stays up. This is far better than your single origin server going down and taking the entire application with it.
Most major CDNs also provide protection against Distributed Denial of Service (DDoS) attacks. They can absorb huge volumes of malicious traffic at the edge, preventing it from ever reaching and overwhelming your origin server. This is a critical availability feature that's nearly impossible to build yourself.
The trap: Don't assume a CDN makes your application fully available if the origin goes down. If the CDN has a cache miss for a critical asset, and your origin is offline, the request will fail. A CDN primarily improves availability for cached static assets. Dynamic API calls will still fail.
Offload the Origin to Cut Costs and Handle Scale
Every request for a static asset that a CDN handles is a request your origin server doesn't have to. This is called origin offload.
For static assets like images, CSS, and JS bundles, you can achieve cache hit ratios of 95% or higher. This means only 5% of requests for those assets ever reach your server. This drastically reduces the load, bandwidth, and compute costs for your origin infrastructure.
It also frees up your origin servers to do what they're best at: handling dynamic, non-cacheable requests like API calls and server-side rendering. By offloading the "dumb" work of serving static files to the CDN, you allow your core application logic to perform better under load.
This is the flow:
How to Configure Your Frontend Build for a CDN
You don't just "turn on" a CDN. Your frontend build process needs to know where to point for assets. The most common way to do this is by configuring a publicPath in your bundler.
This tells your build tool (like Webpack or Vite) to prepend a specific URL to all your generated asset paths.
Here’s a typical Webpack configuration:
// webpack.config.js
import path from 'path';
import { Configuration } from 'webpack';
const config: Configuration = {
mode: 'production',
entry: './src/index.ts',
output: {
// This is the key part.
// All generated asset URLs will start with this prefix.
publicPath: 'https://cdn.example.com/assets/',
// Using [contenthash] is critical for cache busting.
// When a file's content changes, its name changes, forcing a new download.
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
// ... other configs like modules, plugins, etc.
};
export default config;
When you build, your index.html will contain tags like <script src="https://cdn.example.com/assets/main.a1b2c3d4.js"></script>. The browser will fetch the script directly from the CDN, not your origin server.
The trap: Serving assets from a different domain (cdn.example.com) than your main site (www.example.com) can cause Cross-Origin Resource Sharing (CORS) errors. This is especially common with web fonts or when fetching assets via JavaScript. You must configure your CDN to send the correct Access-Control-Allow-Origin HTTP header to avoid this.
Try it
Open your browser's dev tools on a major site like stripe.com or theverge.com. In the Network tab, find a static asset (a JS, CSS, or image file). Inspect its response headers. Can you identify which CDN served it (look for headers like Server, X-Served-By, or cf-ray) and whether it was a cache hit (look for X-Cache, cf-cache-status, or similar)?
Next: We'll cover how CDNs decide what to cache and for how long in CDN Cache Behavior and Invalidation.
Lock it in — apply this lesson under interview conditions.