CDNs in system design interviews
A content delivery network (CDN) is a fleet of cache servers placed in many locations close to users, which serve copies of your content so most requests never reach your own servers. In a system design interview, a CDN is the standard answer for static files, images, video and audio segments; the questions that earn credit are what is cacheable, how long it stays fresh, how you change it, and what happens on a miss.
By Evin JohnPublished 7 min read
1. What a CDN is
Your application runs in a few regions; your users are everywhere. Each round trip across an ocean costs tens to hundreds of milliseconds, and serving every image and video byte from your own data centers costs bandwidth and servers. A CDN places caching proxies in many cities. A user's request goes to the nearest one, which returns a stored copy if it has one and otherwise fetches it from your origin (an object store or your web servers), stores it, and returns it. Commercial CDNs also terminate TLS, absorb attacks and run small amounts of code at the edge, but caching is the core idea.
2. Why interviewers ask about it
Any design that serves media or a global audience needs a CDN, and saying "put it on a CDN" without detail is one of the most common hand-waves in system design rounds. Interviewers follow up with: what exactly is cached, what is the TTL, how do you update a file that changed, how do you protect paid content, and what happens to the origin when a new release is requested by millions at once.
3. How a user reaches the right edge
| Method | How it works | Strength | Weakness |
|---|---|---|---|
| DNS-based steering | The CDN's DNS server answers the hostname with the address of a PoP chosen for the resolver's location and the PoP's load | Fine control per request; can avoid overloaded or failed PoPs | Decides by the resolver's location, not the user's; DNS caching delays changes |
| Anycast | Many PoPs announce the same IP address; internet routing delivers packets to the nearest one in network terms | Simple, fast failover when a PoP withdraws its route; strong against DDoS because attack traffic spreads out | Less precise load control; a routing change mid-connection can move a long TCP session |
Many CDNs combine the two. In an interview, one sentence is enough: "Users reach the nearest PoP through anycast or geo-aware DNS, and failed PoPs drop out of rotation."
4. Cache tiers and the origin shield
- Users
- Browsers, apps, players
- Edge PoPs
- Load balancer hashing by URL
- Edge cache servers (memory + SSD)
- Mid tier
- Regional shield cache
- Request collapsing
- Origin
- Object storage
- Application servers for dynamic content
- Within a PoP, consistent hashing on the URL sends each object to the same server, so the PoP's total disk acts as one large cache instead of many copies of the same popular files.
- The shield sits between edges and origin. Without it, a new file requested in 100 PoPs could cause up to 100 origin fetches; with one shield per region, it causes a handful.
- Request collapsing means that if 5,000 users ask an edge for the same uncached object in the same second, the edge sends one request upstream and the rest wait for it.
- Tiered storage at each edge keeps the hottest objects in memory, the warm set on SSD, and evicts the long tail first.
edge egress at peak: 1,000 Gbps (1 Tbps)
hit ratio 95%: origin serves 5% = 50 Gbps
hit ratio 99%: origin serves 1% = 10 Gbps
effect: four points of hit ratio cut origin load five-fold
with a shield at 90% hit: origin sees 10% of edge misses: 5 Gbps or 1 GbpsThis arithmetic is the most useful thing to say about a CDN in an interview. It explains why you add a shield, why long TTLs matter, and why a launch that empties caches is dangerous for the origin.
5. Cache keys, freshness and changing content
The cache key is usually the host plus the path plus some query parameters. Strip parameters that do not change the response (tracking tags), or every variation becomes a separate miss. Freshness is set by the origin's response headers.
| Directive | Meaning | Typical use |
|---|---|---|
max-age=N | Browsers and CDNs may reuse the response for N seconds | Static assets, often with a long N |
s-maxage=N | Overrides max-age for shared caches such as the CDN only | Let the CDN keep an API response briefly while browsers revalidate |
stale-while-revalidate=N | Serve the stale copy for up to N seconds while fetching a fresh one in the background | Popular pages where a few seconds of staleness is fine |
private | Only the user's browser may cache it, never a shared cache | Personalized pages and account data |
no-store | Do not cache anywhere | Sensitive responses |
immutable | The content at this URL will never change | Versioned file names such as app.3f9c1a.js |
- Versioned URLs (preferred). Put a content hash or version in the file name. A deploy publishes new names and updates the HTML that references them; old files simply age out. No purge is needed, and there is never a mix of old and new.
- Purge (invalidation). Ask the CDN to drop a path or a tag from every PoP. Useful for mistakes and legal takedowns, but it takes time to reach every edge, and a broad purge sends a wave of misses to the origin.
- Short TTLs. Fine for content that changes often, at the cost of a lower hit ratio and more origin traffic.
6. Beyond static files
- Video and audio. Media is cut into segments of a few seconds at several bitrates, each one an ordinary cacheable file. The music streaming walk-through and the Netflix walk-through show this at scale; some providers also pre-position popular titles on edge servers before peak hours.
- Large downloads. Range requests let a client fetch part of a file, and edges cache ranges or whole objects depending on configuration.
- Dynamic APIs. Even uncacheable responses gain from a CDN: TLS is terminated near the user, and the edge keeps warm, reused connections to the origin, which cuts handshake time.
- Protected content. Signed URLs or signed cookies carry an expiry and a signature the edge can check without calling your servers, so only paying users fetch premium files.
- Security. Edges absorb volumetric DDoS traffic and can run a web application firewall before requests reach you.
- Live calls are different. Real-time video calls need delays under a second and go through media servers, not a CDN; only a broadcast version with several seconds of delay fits the CDN model. See the video conferencing walk-through.
7. How CDNs show up in common prompts
| Prompt | What the CDN serves | The interesting part |
|---|---|---|
| Music streaming | Audio chunks at several bitrates | Long-tail catalog: edges hold hits, shields hold the middle |
| Netflix | Video segments | Pre-filling edges before peak viewing hours |
| URL shortener | Optionally the redirects themselves | A cached 301 cuts load but hides clicks from analytics |
| E-commerce checkout | Product pages and images | Keeps sale-day browsing away from checkout services |
| API gateway | The edge in front of the gateway | TLS and DDoS absorption before traffic reaches the gateway fleet |
| Caching | One layer among several | How CDN freshness fits with app and database caches |
8. Mistakes to avoid
- Caching personalized responses in a shared cache. A missing
privateor a cache key without the user can show one person's page to another. - Relying on purges for every deploy. Versioned file names are faster and safer.
- Ignoring cold launches. A new release that every user requests at once is all misses; pre-warm the shield and edges, or stagger the rollout.
- Letting query strings fragment the cache. Normalize or ignore parameters that do not affect the response.
- Treating the CDN as storage. The origin remains the source of truth; edges evict whatever they want.
- Forgetting cost and logs. Egress is billed, and edge logs are how you count downloads or plays, so ship them somewhere useful.
9. How to talk about it in the interview
- Say which objects go on the CDN and which never do (personalized or sensitive responses).
- Give the TTL strategy in one sentence: long TTLs with versioned names, short TTLs or purge only where needed.
- Use hit-ratio arithmetic to size the origin.
- Mention the shield and request collapsing when a launch or viral object comes up.
Fictional example
- Interviewer
- A new game update of several gigabytes goes live at 9 a.m. for millions of players. What happens to your origin?
- Candidate
- Without preparation every edge misses at once. I would push the files to the regional shields before 9, so edges fill from shields instead of the origin, and keep request collapsing on so each edge fetches each chunk once. The files have versioned names with long TTLs.
- Interviewer
- And if the origin still struggles?
- Candidate
- Stagger the rollout by region or by percentage of players, which spreads the misses over an hour. The client retries with backoff, and the origin only ever sees shield traffic.
Practicing with Natively
Interviewers ask CDN follow-ups inside almost every design, so practice answering them in two or three sentences. Run a mock call with a friend and keep Natively open on your laptop: it writes down the conversation as it happens and, when you ask, offers points for the question on the table, for example the shield or versioned file names. You can also ask it to draw the tiered request path and check it against your own picture. The transcript you keep makes it easy to see which answers ran long.
Questions people ask
What is a CDN in system design?
A content delivery network is a set of cache servers in many locations close to users. A request goes to the nearest point of presence, which returns a stored copy or fetches it once from your origin and keeps it, so most traffic for static files and media never reaches your own servers.
What is an origin shield in a CDN?
It is a mid-tier cache between the edge locations and your origin. Edges that miss ask the shield instead of the origin, and the shield collapses simultaneous requests for the same object into one origin fetch, so a new or expired file causes a handful of origin requests instead of one per edge.
How do you update a file that is cached on a CDN?
The safest way is to give each version a new file name, usually with a content hash, and update the page that references it; the new URL is fresh everywhere at once and old copies age out. Purging a path from every edge works for urgent fixes but takes time to spread and sends a burst of misses to the origin.
Can a CDN help with dynamic API responses?
Yes, even when the response cannot be cached. The edge terminates TLS close to the user and reuses warm connections to the origin, which cuts connection setup time, and it filters attack traffic. Short shared-cache lifetimes, set with s-maxage, also let it cache some public API responses for a few seconds.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
