Design a CDN: Junior, Senior and Staff Answers
When a hiring manager asks you to design a content-delivery network (CDN), they are looking for three things: your ability to reason about massive scale, your grasp of latency-critical paths, and your awareness of operational risk. A good answer shows you can break a request down into hops, pick the right data stores, and justify every component.
What the interviewer is testing
- Scalability – can you handle millions of requests per day without a single bottleneck?
- Latency awareness – do you know which hop dominates the response time and how to shrink it?
- Operational thinking – do you anticipate cache miss storms, hot-spot eviction, and regional failures?
- Trade-off reasoning – are you comfortable discussing cost vs. performance vs. complexity?
Core requirements and driving numbers
| Requirement | Typical ball-park figure (hedged) |
|---|---|
| Daily request volume | ~10 million requests (≈115 req/s) |
| Cache hit ratio target | 80 % (so 2 M cache misses per day) |
| End-to-end latency goal | ≤50 ms for static assets |
| Data size per object | 100 KB – 5 MB (most static web assets) |
These numbers set the scale of the edge fleet, the size of the origin store, and the bandwidth you need to provision.
The request path, one hop at a time
- DNS resolution – the client resolves
cdn.example.com. Route 53 returns the nearest edge location’s IP. - Edge node – a caching proxy server (for example NGINX) at the edge location receives the HTTP request.
- Cache lookup – the node checks its own cache (an in-memory index over objects held in RAM and on local SSD) for the object key.
- Cache hit – if present, the object is streamed back, hitting the latency target.
- Cache miss – the node forwards the request to the origin tier via an internal VPC load balancer.
- Origin fetch – the origin reads the object from S3 (or Aurora for dynamic assets) and returns it.
- Populate edge cache – the edge node stores the object in its local cache, and a regional cache tier can keep a copy so a restarted node refills without going back to the origin.
- Response – the edge streams the data to the client.
Data model and key choice
The cache key is usually URL + Vary headers (e.g., Accept-Encoding). This deterministic key lets you store a single copy per variant. Alternative designs, like hashing the entire request body, are overkill for static assets and add latency.
What a complete junior answer covers
- Lists the hops above and names the pieces (DNS routing, edge cache, origin load balancer, S3 origin).
- Shows a simple diagram: client → edge → origin.
- Mentions a cache-hit ratio target and rough traffic numbers.
- Briefly touches on TTL-based invalidation.
- Accepts that edge nodes are pre-provisioned; does not dive into autoscaling or regional failover.
What a senior answer adds
- Routing logic – explains geo-DNS, latency-based routing, and how CloudFront edge locations are selected.
- Cache hierarchy – adds a regional cache (e.g., an S3 bucket per region) to reduce origin load.
- Invalidation strategy – combines TTL with explicit purge via S3 event notifications and an SQS queue that triggers edge eviction.
- Consistency – discusses eventual consistency of edge caches and how stale reads are acceptable for static assets.
- Capacity planning – calculates edge bandwidth: 10 M requests × 200 KB avg = 2 TB per day, ≈23 MB/s or about 185 Mbps on average, but peaks may be 10× higher, so the edge fleet needs to handle roughly 2 Gbps.
- Monitoring – CloudWatch metrics for cache hit ratio, latency, and error rates.
What a staff answer adds
- Failure modes – describes edge node crash, regional network partition, and origin outage. Shows how a fallback to another region’s S3 bucket and a retry queue (SQS) keeps traffic flowing.
- Operational tooling – automated cache warm-up scripts, canary deployments of new edge software, and chaos testing with AWS Fault Injection Simulator.
- Cost analysis – compares data transfer out of S3 vs. edge cache egress; shows that a 80 % hit ratio reduces origin bandwidth by roughly 80 %, saving on S3 egress fees.
- Trade-off defense – why you might accept a slightly higher latency (e.g., 60 ms) to simplify cache invalidation, or why you would choose DynamoDB for metadata (object versioning) instead of a relational store.
- Security – signed URLs, WAF integration, and TLS termination at the edge.
Common mistakes that sink the answer
- Skipping the DNS layer – interviewers expect you to mention Route 53 and explain how the client is steered to the nearest edge.
- Treating cache as a black box – you need to discuss key design, TTL, and eviction policy.
- No numbers – without traffic or latency targets, the design feels vague.
- Over-engineering – adding a full micro-service mesh for a simple static-asset CDN signals misunderstanding of scope.
- Ignoring cache miss storms – failing to mention throttling or back-off when the origin is overwhelmed.
Level comparison table
| Aspect | Junior | Senior | Staff |
|---|---|---|---|
| Scope | Basic request flow, single edge cache | Multi-region routing, hierarchical cache, explicit invalidation | Full failure-mode analysis, ops tooling, cost trade-offs |
| Depth | Lists services, shows diagram | Adds routing logic, capacity math, monitoring | Adds chaos testing, automated warm-up, security layers |
| Metrics | Cache hit ratio, latency target | Detailed bandwidth calculations, error rates | Cost breakdown, SLA impact, risk assessment |
| Complexity | Low – one hop beyond origin | Medium – two-level cache, TTL vs. purge | High – resilience, ops, and trade-off justification |
How to practice this
- Study the worked design in the System Design AI library. Read the step-by-step walkthrough and note how each component is justified.
- Sketch your own board on the canvas. Replicate the request path, then add a senior-level routing layer, and finally a staff-level ops overlay.
- Run a mock interview with a peer, or ask the AI coach to review your canvas. Look for feedback on missing failure modes or cost considerations, and iterate.
Questions people ask
What is the main purpose of a CDN?
A CDN moves content closer to the user to reduce latency and offload traffic from the origin, achieving faster response times and lower bandwidth costs.
How do you decide the number of edge locations needed?
Start with traffic volume and latency goals. Roughly 10 M requests per day translates to about 115 requests per second. That is a small load, so the number of edge locations is set by where your users are and by the latency goal, not by throughput; size each location for its share of peak traffic.
Why keep the edge cache on the node itself instead of reading from S3 each time?
A lookup in the node’s own memory and local disk takes well under a millisecond, which is what makes the 50 ms target reachable. S3 is durable but sits a network round trip away, so it is better suited to the origin store.
What is a common failure mode in CDN design?
A cache-miss storm after a purge can overwhelm the origin. Mitigate it with throttling, back-off queues (SQS), and warm-up scripts that pre-populate edge caches.