CDNs in System Design Interviews: When to Use It and What to Say
A content delivery network (CDN) is a geographically distributed cache that stores copies of your static or semi-static assets near the users who request them. In an interview you can frame it as "a set of edge nodes that serve cached content so the client sees lower latency and the origin sees less traffic".
The problem a CDN solves
Imagine you are building a photo-sharing service that serves 100 GB of images per day to users worldwide. Without a CDN, every image request travels from the user’s ISP to your data center, hits your load balancer, and then fetches the file from a storage bucket. If a user in Tokyo requests an image stored in a US-East data center, the round-trip can be 150 ms or more, and the core network sees the full 100 GB of traffic. The latency hurts user experience, and the origin server must scale to handle the global load.
How a CDN works – step by step
- User request – The client resolves
cdn.example.com/image.jpgto an IP address that belongs to the nearest edge node (often via DNS latency-based routing). - Edge cache lookup – The edge node checks its local cache. If the object is present and fresh, it returns the data immediately.
- Cache miss – If the object is missing or stale, the edge node forwards the request to the origin server (your primary storage or application server).
- Origin response – The origin returns the object with HTTP cache-control headers (e.g.,
max-age=86400). - Cache store – The edge node stores the object for the duration specified by the headers.
- Subsequent requests – Future requests from any user that maps to the same edge node hit the cache and are served in milliseconds.
Small worked example
Suppose a user in Berlin requests https://cdn.news.com/article/12345.css. The DNS resolver returns an IP belonging to a European edge node. The edge node checks its LRU cache and finds a fresh copy (cached 2 hours ago, max-age=24 h). It streams the CSS back in ~10 ms. A user in São Paulo later requests the same file; DNS routes the request to a South-America edge node, which misses the cache, forwards to the origin in US-East, receives the file, stores it, and serves the user in ~80 ms. The next request from any South-America user will be fast.
Where CDNs appear in classic interview questions
| Interview question | Typical system component | Where the CDN fits |
|---|---|---|
| Video streaming platform (e.g., YouTube-like) | Media storage & transcoding pipeline | Edge nodes serve the encoded video chunks (HLS/DASH) after the origin pushes them to the CDN. |
| Large-scale static asset serving (e.g., Instagram image service) | Object store (S3) + API gateway | CDN sits in front of the object store, caching thumbnails, full-size images, and CSS/JS. |
| Global API gateway (e.g., a public weather API) | API servers behind a load balancer | CDN can cache read-only JSON responses for a short TTL, reducing API server load and latency. |
In each case the CDN is placed between the client and the origin storage or API. It is the first hop after DNS resolution.
Trade-offs and the alternative interviewer may ask about
| Aspect | CDN advantage | CDN drawback |
|---|---|---|
| Latency | Edge proximity reduces round-trip time dramatically. | Edge node may still be far for some users; latency improvement depends on geographic distribution. |
| Origin load | Offloads the majority of read traffic, allowing a smaller origin cluster. | Cache miss traffic still reaches origin; cache warm-up can cause spikes. |
| Cost | Pay-as-you-go for cache egress; often cheaper than scaling origin horizontally. | Extra cost for cache storage and data transfer; over-caching can waste money. |
| Cache consistency | Simple for immutable assets (e.g., versioned URLs). | Invalidation for mutable content is complex; stale data can hurt UX. |
| Control | CDN providers expose edge functions (e.g., CloudFront Functions, Cloudflare Workers) for limited logic. | You lose fine-grained control over networking stack; custom protocols may not be supported. |
If the interviewer pushes back, be ready to discuss origin-side scaling (adding more web servers, sharding the storage) as the alternative. Explain that scaling the origin solves capacity but does not address latency for distant users, and it incurs higher operational overhead.
30-second spoken pitch
"A CDN is a network of edge caches that store copies of static or semi-static assets close to users. It reduces latency by serving requests from the nearest node and offloads traffic from the origin, which lets you scale more cheaply. In a design you typically place the CDN in front of your object store or API, configure cache-control headers, and rely on DNS-based routing to direct users to the right edge. The main trade-off is cache invalidation and extra cost, so you need to balance freshness against performance."
Common mistakes candidates make
- Treating the CDN as a magic performance booster – Forgetting to mention cache-control headers or TTLs, which are essential for the CDN to actually serve content.
- Skipping the DNS step – Overlooking that the CDN’s edge selection happens at DNS resolution, which influences latency.
- Ignoring cache warm-up – Assuming the edge will always have the object; in reality a cold cache incurs a miss and a round-trip to origin.
- Discussing CDN without a concrete use case – Interviewers expect you to tie the CDN to a specific component (e.g., image service) and explain how it changes the data flow.
- Over-promising consistency – Claiming that the CDN guarantees real-time freshness; you should acknowledge the eventual consistency and the need for versioned URLs or explicit invalidation.
How to practice this
- Study the worked design – In the System Design AI library you can open the worked design for a content delivery network like CloudFront.
- Sketch the request flow – On the canvas, draw the client → DNS → edge cache → origin path, labeling cache hits and misses.
- Run a mock interview – Explain the CDN’s role, trade-offs, and alternatives in under two minutes, then answer follow-up questions about cache invalidation and cost.
Questions people ask
When should I suggest a CDN in a system design interview?
Bring up a CDN when the problem involves serving static or semi-static content to a geographically dispersed user base, especially when latency or origin load is a concern.
What are the key metrics to discuss when evaluating a CDN?
Talk about cache hit ratio, latency reduction (e.g., from 150 ms to 10 ms), origin bandwidth saved, and cost per GB of cache egress.
How do you handle cache invalidation for frequently updated content?
Use short TTLs, versioned URLs, or explicit purge APIs. Explain the trade-off between freshness and cache efficiency.
What alternative can I propose if the interviewer asks why not just scale the origin?
Explain that scaling the origin solves capacity but does not reduce the network distance for distant users, whereas a CDN addresses latency and offloads read traffic.