System Design · Interview breakdown · Free article
Design a CDN (Content Delivery Network)
Send each reader to a nearby server that already has the file, move readers within seconds when a data centre fails, make forty servers hold forty different things, keep a launch from flattening the origin, make a wrong price disappear everywhere, and stop one request from poisoning a page for everyone. Built one step at a time, with experiments you can run.
A CDN is a network of servers in many cities that keeps copies of websites’ files. A reader downloads them from a building nearby, not from the website’s own servers across an ocean. Readers reach a nearby point of presence (PoP) through anycast: every PoP announces the same addresses, and routers deliver each reader to the nearest one. A server stops announcing when its own health check fails, and traffic is split over several address blocks so a dead PoP’s readers land on neighbours with room. Inside a PoP, consistent hashing gives every URL one owner, so forty servers hold forty different slices and a server’s death moves only its own share. Misses collapse into one fetch per PoP, then pass through regional tiers and a shield before the origin. A purge is an entry in a numbered log that every PoP applies in order. A PoP that stops hearing the log asks the origin before serving. A fetch that was on its way when a purge landed is refused. The cache key holds exactly what the origin reads, normalized, and nothing else reaches the origin.
Difficulty: Hard. Also asked as Design Cloudflare, Design Akamai, Design a content delivery network, Design an edge cache.
How do you design a CDN?
A content delivery network, or CDN, is a network of servers in many cities that keeps copies of other websites’ files. When you open a shop’s page, your browser downloads the images, scripts and often the page itself from a CDN building a few kilometres away. The shop’s own servers may be on another continent. Cloudflare, Akamai, Fastly and Amazon CloudFront are CDNs. Each location is called a point of presence, or PoP. The shop’s own servers, where the files come from, are called the origin.
- Point: shop.example → CDN. Thousands of customers’ hostnames, each with its own certificate and rules.
- Visit: Marta opens the page. Her request must reach a nearby PoP, and a live one when that PoP fails.
- Hit: X-Cache: HIT. Forty servers in one PoP must not all keep the same files.
- Launch: 18:00 · 60,000 req/s. A new file is cached nowhere, and every PoP wants it at the same moment.
- Fix: Purged: 150 of 150 PoPs. A wrong price must vanish everywhere, even at a PoP that cannot be reached.
Picture the launch of a running shoe. A sports shop has its servers in northern Virginia, and at 18:00 Central European time it publishes the product page and twelve photos. Marta lives in Frankfurt and has been waiting for this. At 18:00 she opens the page in Polish, her first language, looks at the photos, and at 18:07 she puts the shoes in her basket at €180. The price should have been €130.
Interviewers like this problem because the first answer sounds finished: put servers in many cities, cache files with a time to live, and send misses to the origin. All of it is right. The short answer is about a cache. A CDN is also a routing system that must keep working while its own buildings fail. And it is a fleet of thousands of caches that must forget the same thing at the same time.
Here is the design in brief. The shop points its hostname at the CDN. Every PoP announces the same internet addresses, so the routers between Marta and the CDN deliver her requests to the nearest PoP. There, one of forty servers owns the page’s URL and answers from its disk. On a miss, it asks a larger regional cache, which asks one shield server near the origin, so a file wanted everywhere is fetched from the shop once. A control plane pushes the shop’s settings and its purges to every PoP.
The rest of this page is about the moments that design has to survive.
The first is a building going dark. Later that evening, at 21:40, the Frankfurt PoP loses power while it serves 480 gigabits a second. Marta presses reload. Where her request goes next, and whether the PoP that receives it has room, depends on how readers were routed there in the first place.
The second is the wrong price. The shop fixes it at 18:07. Frankfurt stored the page at 18:00 with a lifetime of an hour. Unless something tells it otherwise, Frankfurt shows €180 until 19:00, and so does every other PoP that stored it at the launch.
What is the interviewer testing?
Most candidates draw PoPs, a cache and an origin, and a mid-level answer can stop there. The interviewer then pushes on what that picture assumes. How does a reader reach a PoP, and what happens when it fails? Why is the hit ratio lower than the disk space suggests? What does the origin see when a new file goes live everywhere? How fast can every PoP forget a file, and what if one of them is unreachable? What decides which readers may share a cached copy?
A senior answer routes readers so that a dead PoP costs seconds, not minutes. It protects the origin with request collapsing, where many readers share one fetch, and with tiers of caches. A staff answer explains why anycast fails differently from DNS, and makes a purge reach a PoP that was cut off when it was sent.
Spend most of the deep-dive time on routing and invalidation. Hashing inside a PoP and the tiers are the usual follow-ups, and cache poisoning comes up whenever the interviewer has worked on security. How to run a round has the time plan for a 45 to 60 minute round and a 15-minute screen.
What should you ask before drawing anything?
Four questions change the design. Ask them in the first two minutes. If the interviewer leaves one open, say your assumption out loud.
- Are we building the CDN, or putting one in front of a website?
- Assume building it: a provider like Cloudflare or Fastly with thousands of customers. Putting a CDN in front of a site is a single box on someone else’s diagram, and a short answer.
- What content?
- Assume files anyone may fetch with a GET: images, scripts, styles, video segments and pages that are the same for every reader. Pages built for one signed-in person are passed through to the origin, not cached.
- How big, and where?
- Assume 150 PoPs on six continents, each with about 40 cache servers. A launch like the shoe’s can send 60,000 requests a second for one file.
- How fast must a change reach every PoP?
- Assume a purge must take effect everywhere within a few seconds, including at a PoP that was unreachable when it was sent. Ask what a customer may see while it spreads.
Functional requirements
1. Serve customers’ files from a nearby PoP 2. On a miss, fetch from the customer’s origin 3. Customers set hostnames, origins, rules 4. Purge by URL or by tag, everywhere, fast 5. Logs and traffic stats per customer out: edge code, video packaging, WAF rules
Say it, don’t write it: Two planes: the data plane serves bytes, the control plane changes what they are.
- Serve each customer’s files to readers from a PoP near them, over HTTPS on the customer’s own hostname.
- When a PoP does not have a file, fetch it from the customer’s origin, keep a copy for as long as the rules allow, and serve it.
- Let customers configure their hostnames, their origin and their caching rules.
- Let customers purge files by URL, or by a tag that groups many URLs, so every PoP stops serving them within seconds.
- Give customers logs and traffic statistics: requests, bytes, hits and errors.
Out of scope
- Running customers’ code at the edge
- Packaging video into streaming formats
- Firewall rules that inspect requests for attacks
- Buying and building the network itself
The five requirements fall into two parts. Serving and fetching are the data plane: the path every request takes, millions of times a second. Configuration, purges and logs are the control plane, which changes what the data plane does. They fail differently. A control plane outage should delay a change, never stop the serving.
Non-functional requirements
• Hit: first byte in tens of ms, not 195 • A PoP dies: readers move within seconds • Origin sees a small share of requests • Purge: every PoP within a few seconds • One reader can never change another’s page • 150 PoPs; one launch can need 80 Gbps
Say it, don’t write it: The origin is far and small; the edge is near and big. Every rule follows from that.
- A cached file’s first byte reaches a reader in tens of milliseconds, wherever they are.
- When a PoP fails, its readers are served elsewhere within seconds.
- The origin sees a small share of requests, even when a new file goes live everywhere at once.
- A purge takes effect at every PoP within a few seconds, and a PoP that missed it does not keep serving the old file.
- One reader’s request can never change what another reader receives.
- 150 PoPs, and single launches that need 80 Gbps.
Two numbers are worth working out now, because they are why a CDN exists. The first is distance. Frankfurt is about 6,500 km from northern Virginia. Light in optical fibre covers about 200 km each millisecond. So a round trip takes at least 2 × 6,500 ÷ 200 = 65 milliseconds, and real fibre never runs straight. A new HTTPS connection needs about three round trips before the first byte arrives: the TCP handshake, the TLS 1.3 handshake and the request. TLS 1.2 needs one more. That is 3 × 65 = 195 milliseconds before Marta sees anything, for every new connection. A PoP a few kilometres away makes those same three round trips in well under a millisecond of travel. Latency across distance works through more of these.
The second is volume. Say 2 million people open the shoe’s page in its first 10 minutes, and each loads 3 MB of page and photos. That is 6 terabytes in 600 seconds: 10 gigabytes a second, or 80 gigabits a second. The shop’s origin sits behind a 10 Gbps link. Without a CDN, the launch does not fit through the door. These are interview assumptions, not measurements of any real shop.
Core entities
Service(id, hostnames, origin, rules, version) Object(key, body, headers, expires, etag, tags) Purge(seq, service, urls or tags, soft?) PoP(id, addresses, config ver, purge seq) LogLine(service, url, status, bytes, hit)
Say it, don’t write it: A purge has a sequence number, and a PoP remembers the last one it applied.
Follow Marta’s request for the product page through the records. The shop is a service: its hostname, shop.example, its origin in Virginia, and its rules, such as “cache product pages for an hour”. Every change to a service makes a new version, and every PoP reports which version it runs.
The cached page is an object. Its key is what decides whether two requests may share it: the hostname, the path and the language. Beside the body it keeps the response headers, the moment it expires, an ETag, which is the origin’s fingerprint of this version, and its tags.
A purge is a numbered entry in a log: sequence 8,812 says “drop /p/trail-runner for shop.example”. A PoP records the last sequence number it has applied, so the control plane can always say which PoPs are behind. A log line records one request: which service, which URL, the status, the bytes sent and whether it was a hit.
| Record | What it holds | Why it is separate |
|---|---|---|
| Service | Hostnames, origin, caching rules, a version | What a customer controls |
| Object | Key, body, headers, expiry, ETag, tags | What a PoP stores and serves |
| Purge | Sequence number, service, URLs or tags, soft or hard | An order every PoP applies in the same sequence |
| PoP | Addresses it announces, config version, last purge applied | Tells the control plane who is behind |
| Log line | Service, URL, status, bytes, hit or miss | Statistics and the customer’s bill |
The one distinction that matters: an object is a copy, and the origin decides what is true. A PoP may lose any object at any time and fetch it again. What it must never do is keep serving a copy the customer has told it to drop.
API
GET https://shop.example/p/trail-runner
PUT /services/{id} {hostnames, origin, rules}
POST /services/{id}/purge {urls or tags}
→ 202 {purge_id, seq}
GET /purges/{id} → 149 of 150 PoPs appliedSay it, don’t write it: A purge answers 202 with a sequence number, and a separate call says how far it has spread.
Readers do not use an API. Marta’s browser sends an ordinary request to the shop’s hostname, and the CDN answers it. Customers use a control API over HTTPS. The calls look like this.
| Call | Returns | Why it looks like this |
|---|---|---|
GET https://shop.example/p/trail-runner | The page, with Cache-Control: max-age=3600 and an ETag | The reader’s browser never knows a CDN answered; the origin’s headers say how long a copy may be kept |
PUT /services/42 {hostnames: ["shop.example"], origin: "origin.shop.example", rules} | 200 {version: 17} | A new version of the whole service, never an edit in place, so a bad change can be rolled back to 16 |
POST /services/42/purge {tags: ["product-4411"]} | 202 {purge_id: "p-77", seq: 8812} | Accepted means written to the purge log; it has not reached anyone yet |
GET /purges/p-77 | {applied: 149, pops: 150, behind: ["lisbon"]} | Progress per PoP, because “accepted” and “done” are different claims |
GET /services/42/stats?from=18:00&to=18:10 | Requests, bytes, hit ratio, errors | Built from the log lines |
Two details are there on purpose. A purge answers 202 at once with a sequence number, because telling 150 PoPs anything takes time, and one of them may be unreachable. And the progress call lists the PoPs that are behind by name. The shop needs to know that 149 of 150 PoPs have dropped the page and one has not.
Step 1: serve a file from a nearby PoP
Before the launch, the shop points shop.example at the CDN with a DNS record, and uploads its certificate, or lets the CDN obtain one. At 18:00 Marta’s browser looks up shop.example. The CDN’s DNS servers answer with the address of a PoP. For now, say they pick one near her resolver: Frankfurt.
Her browser connects to Frankfurt. The PoP finishes the TLS handshake with the shop’s certificate, so her encrypted connection ends a few kilometres from her home. Then it reads her request for /p/trail-runner. A server builds the cache key from the hostname and the path and looks it up on its disk.
On a hit, it sends the stored page. The share of requests answered this way is the hit ratio. On a miss, it fetches the page from the origin over a connection it keeps open to Virginia. The three round trips of a new connection are then paid once, not per reader. It stores the page for as long as the origin’s Cache-Control header allows, an hour here, and sends it to Marta. CDN edge caching covers hits, misses and lifetimes in more depth.
This is a pull CDN: a PoP fetches a file the first time someone asks for it. The other kind is push, where the customer uploads files to the CDN in advance. Push suits a small set of large files known ahead of time, such as a game’s installer. Pull suits a shop with millions of files, most of which nobody asks for in any given PoP, which is why this design pulls.
The interactive version of this example is available when JavaScript loads.
A fresh copy is served without asking the origin. After its hour, the copy is stale, but it is not useless. The PoP can ask the origin “has this changed?” by sending the ETag in an If-None-Match header. If nothing changed, the origin answers 304 Not Modified with no body, and the PoP keeps its copy for another hour.
Step 2: customers configure their service and purge files
The shop’s engineer, Oskar, sets up the service through the control API: the hostname, the origin, and a rule that product pages may be cached for an hour. The control plane stores it as version 17 and pushes it to every PoP. Each PoP reports the version it runs, so a change can be watched as it spreads and rolled back if it goes wrong.
Purges travel the same way. Oskar calls the purge API, the control plane writes the purge down, and sends it to every PoP. The purge deep dive shows why “sends it to every PoP” is where most of the difficulty lives.
The interactive version of this example is available when JavaScript loads.
A PoP keeps the last configuration it received. If the control plane goes down, every PoP carries on serving with what it has, and changes wait until it returns. The purge deep dive shows how a PoP tells a quiet control plane from a link that is cut.
Step 3: logs and statistics
Every request a PoP serves produces a log line: the service, the URL, the status, the bytes sent, and hit or miss. The lines stream from every PoP into a log pipeline. From there they are counted by customer and by minute, which gives Oskar his traffic graphs and the CDN its bill, since customers pay by the bytes delivered.
The interactive version of this example is available when JavaScript loads.
On a normal day this already works. The deep dives take it through five moments: a PoP that goes dark, forty servers that each hold the same files, a launch that lands everywhere at once, a price that must disappear, and a request that poisons a page.
A PoP goes dark. Where do its readers go, and how fast?
At 21:40 the Frankfurt PoP loses power. It was serving 480 gigabits a second, 80% of its 600. Its neighbours are Amsterdam, serving 300 of its 600, and Paris, serving 240 of its 600. Marta’s page stops loading, and she presses reload. Where her reload goes depends on how her browser found Frankfurt in the first place.
The first answer uses DNS, as step 1 did. The CDN’s DNS servers answer each lookup with the address of a PoP near the reader. Probes outside each PoP fetch a test file through it every 5 seconds. Two failures in a row mark the PoP down. So within 10 seconds of the power cut, the DNS servers stop handing out Frankfurt’s address.
Play Marta’s reload. The answer named only Frankfurt’s address, and her browser does not ask DNS again. It asked at 21:39:50, and the answer had a time to live of 60 seconds. Her browser and her internet provider’s resolver both keep Frankfurt’s address until 21:40:50, so her reload fails. Now take a reader who looked up the address at 21:40:09, just before the probes noticed. That answer lives until 21:41:09. So Frankfurt’s readers keep failing for up to 70 seconds: 10 for the probes to notice, then up to 60 for the last answers to expire.
Some readers wait longer, because not every resolver obeys the time to live. A 2023 study found that 8.74% of the resolvers it measured “extend the TTL arbitrarily” (Bhowmick et al.).
DNS also locates the wrong machine. A lookup reaches the CDN from the reader’s resolver, not from the reader. A reader in Frankfurt who uses a public resolver in another country can be sent to that country’s PoP. An extension called EDNS Client Subnet lets the resolver pass on part of the reader’s address, so the answer can be “tailored” to the reader (RFC 7871).
In return, DNS can put readers where there is room. Frankfurt, Amsterdam and Paris together carry 480 + 300 + 240 = 1,020 Gbps. The two survivors can take 600 + 600 = 1,200. So the control plane fills both to 1,020 ÷ 1,200 = 85%. That sends 210 Gbps more to Amsterdam and 270 more to Paris, and neither is overloaded. The price is the minute of failures before readers arrive there. A shorter time to live shortens that minute. Each expiry then costs every reader another lookup, which delays their page. DNS explains lookups and their caches.
The second answer is anycast. BGP is the protocol routers use to tell each other which addresses they can reach. With anycast, every PoP announces the same block of addresses over BGP. The routers between Marta and the CDN hear the block from many places. Each router picks the route its own policies prefer, usually the nearest, which for Marta ends at Frankfurt. No DNS answer names a PoP, because every PoP has the same address.
Replay the power cut. Frankfurt’s routers go dark, and the routers connected to them notice. Where the link goes down, they notice at once. Over the shared switch at an exchange, where many networks meet, the link stays up. There a router notices only when BFD, a fast liveness check between routers, stops getting answers. Without BFD, BGP waits for its hold timer, often 90 seconds or more. With it, the routers near Marta switch to the next best route, usually within seconds. A change can still take tens of seconds to settle across the whole internet. Cloudflare, whose network works this way, writes that “we can take an entire data center offline and traffic will automatically flow to the next closest data center” (Cloudflare). Marta’s reload reaches a live PoP. No cached DNS answer holds her at the dead one.
Now follow the routes. Routers pick the next best path, and they know nothing about load. Say that for three quarters of Frankfurt’s readers the next path ends in Amsterdam, and for the rest in Paris. Amsterdam then receives 300 + 480 × 3 ÷ 4 = 660 Gbps, and it can serve 600. It drops 60 of every 660 requests, about 9%, and its own readers lose requests too. If Amsterdam fails under that load, its readers move again, to wherever the routers point next. Routes are only roughly right even on a calm day. A study of Microsoft’s anycast CDN found that it “directs roughly 20% of clients to a suboptimal front-end” (Calder et al.).
The move also costs cache. Amsterdam’s disks hold what Amsterdam’s readers ask for. Frankfurt’s readers ask for their own less popular files, which Amsterdam has never stored. Its misses rise just when it has the least spare capacity to fetch them.
Now change the failure. Frankfurt keeps its power, but a bad software release crashes its cache servers. Its routers stay up. Routers announce the addresses they can reach, and they can still reach the building, so the announcements continue. Readers keep arriving at a PoP where nothing answers. DNS would have noticed within 10 seconds, because its probes fetch a real file. Plain anycast notices when an alert fires and a person withdraws the routes, say 4 minutes later.
That is the difference in the failure model. With DNS, a health check decides where readers go, and it acts in about a minute. With anycast, routers decide, and where a dropped link or BFD tells them, they act in seconds. But routers only know whether a path to the building exists. They cannot tell whether the building can serve, or whether the next building has room.
A route can also change in the middle of a connection. The packets of Marta’s half-finished download then arrive at a PoP that has never seen her connection, and that PoP answers with a reset. The IETF’s document on anycast warns that TCP, “without modification”, will “fail probabilistically, but possibly catastrophically” when routes move under it (RFC 7094). A page that loads in 20 milliseconds rarely notices. A large download has to resume with a range request, which asks for the file from a given byte onward.
The fix keeps anycast and supplies what routers cannot see. The first part is health. Each cache server fetches a test file from its own cache every second. After three failures in a row, the server stops announcing the address block. When the last server in a PoP stops, the PoP drops out of the routes. Cloudflare describes the same arrangement: “If a server crashes, Bird stops announcing the BGP route to the router” (Cloudflare). Bird is the routing program on each server. Replay the crash. The servers stop announcing within 3 seconds and send their routers a withdrawal. The routes move a few seconds later, faster than after a power cut without BFD.
A health check can also be wrong everywhere at once. In 2021 Facebook’s DNS servers were built to withdraw their routes when they could not reach Facebook’s data centres. When its backbone failed, the locations “declare themselves unhealthy and withdraw those BGP advertisements”, and the servers “became unreachable even though they were still operational” (Facebook). So withdrawal needs limits. A server’s health check tests only the server itself, never a dependency elsewhere. Each server also reads, from the control plane’s last message, how many PoPs are already withdrawn, and keeps announcing if too many are. And a PoP that is merely busy never withdraws, because its readers would pile onto the next PoP. It turns away the excess requests instead.
The second part is load. The CDN announces two address blocks instead of one. Block A is announced from Frankfurt, Amsterdam and the PoPs to the north. Block B is announced from Frankfurt, Paris and the PoPs to the south. The CDN’s DNS gives each reader a block that their nearest PoP announces. Readers near Amsterdam get block A, and readers near Paris get block B. Readers near Frankfurt get block A for half of the hostnames and block B for the other half, so each block carries about half of Frankfurt’s traffic. DNS now chooses only the block, and it changes that slowly, for load. The routers still handle the failure. LinkedIn uses a related design it calls regional anycast, with one block per continent handed out by DNS. It moved to that after a single block sent some countries’ readers to distant PoPs (LinkedIn).
Replay the power cut. Frankfurt’s block A readers move to Amsterdam and its block B readers to Paris, 240 Gbps each. Amsterdam carries 540, 90% of its 600, and Paris carries 480, 80%. Nothing is dropped. The split is planned rather than guaranteed, because other networks’ routers choose among the PoPs announcing a block, and their choices can surprise the CDN. So capacity planning has a clear rule: each PoP keeps enough spare room for its share of a neighbour’s readers. A PoP that runs hot can also stop announcing one block, which moves that block’s readers to its next PoP.
The interactive version of this example is available when JavaScript loads.
The experiment plays the failure three ways. Pick a power cut or a software crash. The tabs are DNS with a 60-second time to live, anycast with one address block, and anycast with two blocks and announcements tied to server health.
The interactive version of this example is available when JavaScript loads.
The gap: A reader’s route to a PoP is decided before the PoP fails, and it has to change in seconds.
Option 1: DNS steering
DNS answers each lookup with a nearby PoP, and stops naming one when outside probes fail.
Works when: The control plane needs to place load exactly, and a minute of failures is acceptable.
Breaks when: Readers hold the dead PoP’s address for its time to live: 70 seconds of failures here, and longer behind resolvers that ignore it.
Option 2: Anycast, one address block
Every PoP announces the same addresses, and routers send each reader to the nearest.
Works when: Every neighbour has room for all of a failed PoP’s readers.
Breaks when: Routing ignores load: Amsterdam gets 660 Gbps for 600, and a PoP whose servers crashed keeps receiving readers.
Option 3: Anycast, split blocks, health-driven (start here)
Servers announce only while their own health check passes, and two address blocks send a dead PoP’s readers to different neighbours.
Works when: Any CDN with several PoPs in each region.
Watch for: Every PoP needs spare room for its share of a neighbour, and a long download breaks when its route changes.
In the interview: Open with the power cut and ask how the reader got there. Give DNS its minute, then anycast its speed. Then say the two things routers cannot see, health and load, and how the design gives them both. Mention the crashed-servers case before the interviewer does.
Say this: Readers reach a PoP by anycast, so a dead PoP’s routes disappear and its readers move in seconds, with no cached DNS answer pointing at it. Routers only know whether a path exists, so each server stops announcing when its own health check fails, and a software crash looks like a power cut. Traffic is split over two address blocks, so a dead PoP’s readers land on two neighbours, and each PoP keeps room for its share. DNS still places load, slowly, by choosing a hostname’s block.
Forty servers in one PoP. Why do they hold only one server’s worth of files?
Frankfurt has 40 cache servers. Each has 2.5 TB of disk for the cache, room for 5 million objects of about 500 KB. Together that is 100 TB, 200 million objects. Over a day, the PoP is asked for about 400 million different objects, 200 TB. They are not asked for equally. A few are asked for constantly, and most hardly ever. Say the object ranked i is asked for in proportion to 1 ÷ i to the power 0.8. Web requests follow a curve of this shape, “a Zipf-like distribution with the exponent varying from trace to trace” (Breslau et al.). At the peak, Frankfurt answers 120,000 requests a second. At 500 KB each, that is its 480 gigabits a second.
The first answer puts a load balancer in front and spreads requests evenly over the 40 servers. Follow one photo. Marta’s request for it goes to server 12, which fetches it and keeps it. The next reader’s request for the same photo goes to server 31, which fetches it again. Every server sees the same mix of requests. So every server ends up keeping the same 5 million most-requested objects.
The cost can be computed. Add up 1 ÷ i to the power 0.8 for the top 5 million objects, and divide by the same sum over all 400 million. That is the share of requests that ask for one of the top 5 million: 40.6%. A cache that keeps exactly those objects answers 40.6% of requests. Real eviction policies do a little worse, since they have to guess which objects those are. The PoP has room for 200 million objects and holds 5 million distinct ones. The other 59.4% of requests miss, and 71,251 a second go upstream.
The fix sends every request for one object to the same server. The load balancer hashes the URL and picks server number hash mod 40. Every request for Marta’s photo now lands on one server, which fetches it once. The 40 servers hold 40 different slices, 200 million distinct objects. The same sum for the top 200 million gives a hit ratio of 86.8%. Now 15,801 misses a second go upstream, about a fifth of before. A burst of requests for one new file also meets at one server now, which matters in the launch deep dive.
Now server 17 dies, and the balancer switches to hash mod 39. An object stays on the same server only if its hash mod 40 equals its hash mod 39. That is true for 1 object in 40. The other 97.5% are now looked up on a server that has never held them. The hit ratio drops to 2.2%, and 117,395 misses a second go upstream at once. Adding a server does the same.
Consistent hashing avoids that. Picture the hash values as points on a circle. Each server takes a hundred points of its own around the circle. An object belongs to the first server point after its hash. When server 17 dies, its points disappear. Only the objects that belonged to it move, each to the next point along. That is 1 object in 40, 2.5%, spread over the other 39 servers. The hit ratio right after is 84.7%, with 18,406 misses a second. It climbs back as the moved objects are fetched again. Rendezvous hashing, which scores every server for each URL and picks the highest, is the other common choice, with the same effect. Consistent hashing was invented for web caches. Its 1997 paper says the work “was originally motivated by the problem of hot spots on the World Wide Web” (Karger et al.). Consistent hashing shows the circle step by step.
One owner per file has a weak spot: a file hot enough to overload one server. The shoe’s photo is not one. Frankfurt’s share of its requests at the launch is about 400 a second, 500 KB each: under 2 gigabits a second, which one server sends easily. A 4 GB game update released to everyone at once is different. Say it is a quarter of the bytes Frankfurt sends for an hour. Every request for it lands on its one owner, so one server carries a quarter of the load while 39 share the rest. So a PoP works in two layers. The load balancer now sends a request to any server, not to the owner. That server first checks its own copy of the hottest files, kept in memory or on its own disk. Every server keeps a copy of those. Only if the file is not there does it ask the file’s owner. The hottest files are then served by all 40 servers, and everything else by its one owner. A purge now has to reach every server’s memory, not only the owner’s disk. Hot key mitigation covers the same idea for databases.
The disk has one more problem. Most objects are asked for once and never again. In one Akamai cluster, “74% of the roughly 400 million objects in cache were accessed only once” (Maggs and Sitaraman). Storing each of them pushes out an object that would have been asked for again. So a server can wait for a second request before storing an object. In that cluster, this raised the share of bytes served from cache by about nine points, to 83%, and cut disk writes by 44%.
Akamai measured that result in bytes. A request hit ratio of 90% can come from small icons while large videos miss, and then the origin still sends most of the bytes. Measure the share of bytes as well as the share of requests.
The experiment shows what Frankfurt’s 40 servers hold. Pick a normal hour or the death of one server. The tabs are spreading at random, hash mod 40, and consistent hashing.
The interactive version of this example is available when JavaScript loads.
The gap: Forty servers are one cache only if each object has one home, and a server’s death must not move the others.
Option 1: Spread at random
A load balancer sends each request to any server.
Works when: Each server can hold nearly everything the PoP is asked for.
Breaks when: Every server keeps the same popular files: 5 million distinct objects, a 40.6% hit ratio.
Option 2: Hash mod N
Server number hash of the URL mod 40 owns each object.
Works when: The number of servers never changes.
Breaks when: One death moves 97.5% of objects: the hit ratio falls from 86.8% to 2.2% at once.
Option 3: Consistent hashing, hot files everywhere (start here)
Each object has one owner on a ring of server points; every server also keeps the hottest files in memory.
Works when: Any PoP with more than a few servers.
Watch for: A new owner starts cold after a death, and a file that turns hot needs a moment to reach every server’s memory.
In the interview: Open with the forty identical copies, because it is the surprise. Then give hash mod N and kill a server. Consistent hashing is the fix, and the hot file is the follow-up that shows you know what one owner costs.
Say this: Inside a PoP, each URL is hashed onto a ring of server points, so each object has one owner and forty servers hold forty different slices. A server’s death moves only its own objects, one in forty. Every server also keeps the hottest files in memory, so one popular file does not overload its owner. Servers store an object on its second request, and I track hit ratio by bytes as well as by requests.
The page goes live at 18:00. Why does the origin fall over?
At 18:00 the shop publishes the product page and its twelve photos. Nothing is cached anywhere, because the files did not exist a minute ago. In the first second, 60,000 requests for the main photo arrive across 150 PoPs. The origin takes 200 milliseconds to send the first copy, and it can serve about 2,000 requests a second.
Play it with no coordination. Every request that arrives before a copy lands is a miss, and every miss goes to the origin. In 200 milliseconds, 60,000 × 0.2 = 12,000 requests arrive. That is 12,000 fetches in a fifth of a second, a rate of 60,000 a second, against an origin that serves 2,000. The origin slows down. While it slows, copies take longer to arrive, so more requests find nothing cached, and more fetches pile on.
The first fix is request collapsing. A server that is already fetching the photo makes every later request for it wait for that one fetch. When the copy arrives, it answers them all from it. Replay the launch with collapsing on every server. The 12,000 requests land at random on 150 × 40 = 6,000 servers, 2 each on average. A server gets none of them with a probability of e to the power −2, about 13.5%. So about 5,188 servers see at least one request, and each fetches once. That is 5,188 fetches in the window, a rate of 25,940 a second, still 13 times what the origin can serve.
Now add the hashing from the last deep dive. Inside each PoP, every miss for the photo reaches its one owner, so collapsing happens once per PoP. That is 150 fetches in the window, a rate of 750 a second. The origin serves 2,000 a second, so the photo fits. The launch has thirteen files, though: the page and twelve photos, 13 × 150 = 1,950 fetches. Browsers ask for the page first and the photos after it, so these spread over about a second, close to the origin’s 2,000. The owners inside each PoP make the launch survivable. The tiers, next, give it room.
The waiting requests are answered from the one fetch only if its response may be shared. Say the launch page sets a cookie by mistake and is marked private. Then, as Fastly’s documentation warns, “each of the queued requests must then be sent to the backend independently” (Fastly). Collapsing then stops working during the launch itself.
Quiet files fail in a different way. Take a photo of the shoe in another colour, asked for 300 times an hour worldwide, with a lifetime of 10 minutes. Spread over 150 PoPs, each PoP sees it 2 times an hour. When a request finds no copy, the PoP fetches one and keeps it for 10 minutes. Requests arrive at random, so each miss is followed on average by 2 × 10 ÷ 60 = 1/3 of a hit. The hit ratio is (1/3) ÷ (1 + 1/3) = 25%. The origin receives 225 fetches an hour for a photo asked for 300 times. Without an owner inside each PoP, each server sees a fortieth of its PoP’s requests. The hit ratio drops under 1%, and the origin gets about 298.
A shop has millions of files like this, and a CDN has thousands of shops. Adding PoPs makes it worse, because each PoP’s share of a quiet file shrinks.
So the misses have to meet before they reach the origin. The 150 PoPs are grouped under 6 regional tiers, larger caches that each serve about 25 PoPs. A PoP sends its misses to its tier, not to the origin. Each tier hashes URLs to owners inside it, as a PoP does, so it collapses misses too. The PoPs miss 225 times an hour between them, so each tier sees 225 ÷ 6 = 37.5 requests an hour for the quiet photo. Each miss there is followed on average by 37.5 × 10 ÷ 60 = 6.25 hits, so the tier’s hit ratio is 6.25 ÷ 7.25 = 86.2%.
The six tiers still miss about 31 times an hour between them. Those misses go to one shield, a cache in front of the origin, in the origin’s region. The shield keeps its copies for the same 10 minutes and catches 83.8% of the 31. The origin sees about 5 fetches an hour for the quiet photo instead of 225. AWS describes its version, Origin Shield, the same way: requests for the same object are consolidated, “resulting in as few as one request going to your origin” (AWS). On the launch, the 150 owners’ fetches meet at the tiers and then at the shield, so the origin sends the main photo once.
These numbers are generous to the PoPs. A copy from a tier arrives with its age, and on average about half its 10 minutes are gone. A PoP keeps it only for what is left. PoP hit ratios come out well under 25%. The origin’s 5 fetches an hour are what the tiers buy.
The tiers cost a hop on every miss. For a PoP in the same city as its tier, that is under a millisecond. For a PoP in Sydney whose shield is in Virginia, a miss crosses the world, so tiers are regional and only the last step goes to the shield. All the misses meet at the shield, so it needs a stand-in. If it fails, the tiers send their misses to a second shield, in another region. Sending them straight to the origin would bring back the launch problem.
A popular page has a related problem when its lifetime runs out. Every PoP stored the product page within a second of 18:00. An hour later it expires in all of them together, and thousands of readers find it stale at once. With stale-while-revalidate, each PoP serves the old copy for a few more seconds while one request fetches the new one. Caching covers lifetimes and refreshes.
The interactive version of this example is available when JavaScript loads.
The experiment plays the launch and the quiet photo. Pick one. The tabs are no collapsing, collapsing on each server, one owner per PoP, and regional tiers with a shield.
The interactive version of this example is available when JavaScript loads.
The gap: A file that no PoP holds is wanted by many PoPs at once, and a quiet file is wanted too rarely by any one PoP to stay cached.
Option 1: Every miss goes to the origin
Each request that finds nothing cached fetches from the origin.
Works when: A handful of PoPs in front of an origin much larger than its traffic.
Breaks when: The launch sends 12,000 fetches in 200 milliseconds to an origin that serves 2,000 a second.
Option 2: Collapse on each server
A server fetches a missing file once and makes later requests wait for it.
Works when: One cache server per PoP.
Breaks when: With 6,000 servers, the launch still sends about 5,188 fetches, 25,940 a second.
Option 3: One owner per PoP
Hashing sends each file to one server in the PoP, which collapses its requests.
Works when: Popular files, and origins that can take one fetch per PoP.
Breaks when: A quiet photo reaches each PoP twice an hour: 25% hits, and 225 origin fetches for 300 requests.
Option 4: Regional tiers and a shield (start here)
PoPs send misses to one of 6 regional tiers, and tiers to one shield by the origin, collapsing at every level.
Works when: Any CDN with more than a few PoPs.
Watch for: A miss takes an extra hop, and the shield needs a stand-in so its failure never sends every miss to the origin.
In the interview: Open with the launch arithmetic: 12,000 fetches in a fifth of a second. Then collapse, and show that per-server collapsing is not enough. Then say the quiet file out loud, because it is why tiers exist, and put the shield in front of the origin with a stand-in.
Say this: A new file is cached nowhere, so every PoP misses at once. Each PoP’s owner for the URL collapses its requests into one fetch, and PoPs send misses to regional tiers, which send theirs to one shield in front of the origin, so the origin sees the launch once. The tiers also keep quiet files cached where demand from many PoPs meets: 5 origin fetches an hour instead of 225 for a photo asked for 300 times. The shield has a stand-in, so its failure never turns into every miss at once.
A wrong price is live. How fast can 150 PoPs forget it?
At 18:07, Marta’s basket says €180. The shoe should cost €130. Oskar fixes the price at the origin, and at 18:07:00 he asks the CDN to drop the page. Frankfurt stored the product page at 18:00, with a lifetime of an hour. Left alone, Frankfurt serves €180 until 19:00, and so does every other PoP that stored it at the launch. For an hour, customers would buy at the wrong price.
The first answer is a purge that deletes the page everywhere. Oskar calls the purge API. The control plane sends “delete /p/trail-runner” to all 150 PoPs, and each PoP deletes its copy. Frankfurt drops its copy 0.1 seconds after the call. Fastly and Cloudflare both report a median of about 150 milliseconds to purge worldwide (Fastly, Cloudflare). Fastly notes that light needs about 65 milliseconds to travel from one side of the planet to the other. In fibre it takes closer to 100. Marta reloads, Frankfurt misses, fetches the page again and shows €130.
The purge has to come after the fix. Say the origin runs three servers behind a load balancer and Oskar’s fix reaches one of them a second before the others. A fetch that lands on another server in that second still reads €180, so Oskar purges only once every origin server has the new price.
Now make one PoP unreachable. Lisbon’s link to the control plane goes down at 18:07 and comes back two minutes later. Lisbon can still reach the origin; only its link to the control plane is down. The delete was sent while the link was down, and nothing sends it again. Lisbon never hears about the purge and serves €180 until 19:00.
The fix is a purge log. Each purge becomes an entry with a sequence number: this one is 8,812. The control plane sends entries to every PoP in order. Each PoP remembers the last number it applied, and the control plane records each PoP’s number. When Lisbon’s link comes back, Lisbon reports that its last entry was 8,811, and the control plane sends it everything after that. The purge API can now answer honestly: 149 of 150 PoPs have applied 8,812, and Lisbon has not.
That still leaves the two minutes. Lisbon served €180 the whole time, because it did not know it was behind. So the log also carries a heartbeat. Every second, the control plane tells each PoP the latest sequence number, even when there is nothing new. A PoP that hears nothing for 10 seconds stops trusting its copies of anything that can be purged. Before serving one, it asks the origin directly whether it changed, with the ETag in an If-None-Match header. The origin sends the new page, and Lisbon shows €130 from 10 seconds after its link broke. The cost is one question to the origin each time Lisbon serves a purgeable page while it is cut off. Concurrent requests for one page share one question.
That cost would be large if the control plane itself went quiet, because all 150 PoPs would start asking the origin at once. So the log is copied to a few replicas in different regions, and each sends heartbeats. A PoP asks the origin only when it hears none of them. A purge is accepted only once the replicas hold it. So if the log’s writer goes down, the replicas can truthfully keep saying that nothing is new.
The log has to reach more than the PoPs. Frankfurt drops its copy, misses, and asks its regional tier. If the tier has not applied entry 8,812 yet, it answers with its own copy, and €180 is back. So the tiers and the shield apply the same log, and so does every server in a PoP, since each keeps hot files in memory. A fetch after a purge carries the log position it needs, in a request header. A tier that has not reached 8,812 passes the request up instead of answering it.
One price appears on many pages: the product page, the “Running” category, the search results, and the same pages in four languages. Purging them one URL at a time means knowing every URL, and missing one leaves €180 somewhere. So the origin labels its responses with tags, in a header such as Surrogate-Key: product-4411 category-running. Each PoP keeps an index from each tag to the keys that carry it, and Oskar purges the tag product-4411 once. Fastly calls these surrogate keys, which “allow you to selectively purge related content” (Fastly).
Tags open one more way for the old price to come back. Nobody in Frankfurt had asked for the “Running” category page yet. At 18:06:59.6 someone does, and Frankfurt starts fetching it. The origin reads €180 and begins sending the page. Oskar’s fix lands at 18:06:59.9, and his tag purge reaches Frankfurt at 18:07:00.1. The tag index knows nothing about the category page, because its tags arrive with its response, which is still on the way. At 18:07:00.3 the fetch finishes and stores €180, fresh for an hour. The purge ran, and Frankfurt shows €180 on that page until 19:07.
The fix uses the log again. When a fetch starts, it records the last entry Frankfurt has applied, 8,811. When the fetch finishes, Frankfurt checks the entries applied since then against the page’s URL and the tags the response carries. Entry 8,812 names product-4411, one of those tags, so the copy is thrown away, and the next request fetches €130. Each cache keeps the last few minutes of entries for this check. A counter kept per key could not do it, because a purge by tag cannot find a copy whose tags have not arrived yet.
The check also covers readers who were waiting on that fetch. Those who joined before the purge landed get that copy, as they would have from a cache a moment earlier. Those who join after it get a new fetch, not the refused copy.
Some files never need a purge. The shop’s build gives each photo a name that includes a fingerprint of its content, such as hero.a31f.webp. A new photo gets a new name, and the page links to the new name. Nothing asks for the old name once the pages have moved on, so the old file can stay cached. Files named this way can have a lifetime of a year, with no purge and no revalidation. The origin can say so with Cache-Control: immutable, which marks a response that “will not be updated during” its lifetime (RFC 8246).
A purge can also mark a copy stale instead of deleting it. That is a soft purge. If the response allows stale-while-revalidate, the next request gets the stale copy while one fetch gets the new one. It matters when a customer purges everything at once. After a hard purge of everything, every reader of every file misses together. Collapsing still fetches each file once, but every reader waits for that fetch, and each fetch is a full download. Fastly’s documentation warns that purging a lot of content from a busy service “is likely to result in a rapid increase in traffic to origin” (Fastly). After a soft purge, readers keep getting stale copies without waiting, and each refresh can be a short 304 Not Modified when the file has not changed. A price error still needs a hard purge, because each extra view of €180 is another order at the wrong price.
The interactive version of this example is available when JavaScript loads.
The experiment plays the purge. Pick whether every PoP is reachable, Lisbon is cut off, or a fetch is on its way when the purge lands. The tabs are waiting for the lifetime, deleting everywhere, and a numbered log with a heartbeat and a check on fetches in flight.
The interactive version of this example is available when JavaScript loads.
The gap: A purge must reach every PoP, including one that cannot hear it, and a fetch that started before it must not undo it.
Option 1: Wait for the lifetime
Fix the origin and let every copy expire.
Works when: Files cached for seconds, or files with versioned names.
Breaks when: A page cached for an hour shows €180 until 19:05.
Option 2: Delete everywhere, once
The control plane sends a delete to every PoP.
Works when: Every PoP is reachable and no fetch is in flight.
Breaks when: An unreachable PoP never hears it, a tier can hand the old page straight back, and a fetch that started before it stores the old page again.
Option 3: A numbered log, heartbeat and fetch check (start here)
Every cache applies purges from a numbered log and catches up after an outage; silence for 10 seconds means ask the origin; a fetch is refused if a purge landed while it was on its way.
Works when: Anything that can be purged.
Watch for: A cut-off PoP sends the origin a revalidation for each page until it hears the log again.
In the interview: Open with the hour of €180. Give the delete, then cut Lisbon off, then play the fetch that lands after the delete. The log, the heartbeat and the fetch check answer one each. Mention tags and versioned file names before the interviewer asks how Oskar knows every URL.
Say this: A purge is an entry in a numbered log. Every PoP applies entries in order and reports the last one it applied, so a PoP that was cut off catches up when it returns, and the API can say which PoPs are behind. A PoP that hears nothing for 10 seconds revalidates before serving, which bounds how long it can be wrong. A fetch remembers the last entry applied when it began, so one that was on its way when the purge landed cannot store the old copy. Tags purge every page that shows a price, and files with versioned names never need purging.
One request poisons the page for everyone. How?
At 18:20, Marta reloads the product page, and it is in German. The shop’s origin chooses the language from the Accept-Language header the browser sends. Frankfurt’s cache key is the hostname and the path. The origin should send Vary: Accept-Language with the page, a header telling caches that the response depends on the request’s language. It does not. Lukas, in Frankfurt too, was the first reader there to ask for the page after the 18:07 purge, and he asked in German. The origin sent the German page, and Frankfurt stored it under a key that did not mention language. Marta’s request found that key and got his page.
The same gap has a worse use. The origin builds the links to its scripts from another header, X-Forwarded-Host, which a proxy normally sets to the original hostname. An attacker waits for a moment when Frankfurt has no copy, such as just after a purge, and sends one request for the product page with X-Forwarded-Host: evil.example. The request misses and goes to the origin with that header attached. The origin builds a page whose script comes from https://evil.example/app.js, and Frankfurt stores it under the ordinary key. For the next hour, every reader in Frankfurt runs the attacker’s script. The attacker never touched the shop or the CDN. They found an input the origin reads and the cache does not. This is called web cache poisoning. PortSwigger’s research on it puts the problem in one line: “any difference in the response triggered by an unkeyed input may be stored and served to other users” (PortSwigger).
The first fix is to have the origin send Vary: Accept-Language, and to add that header to the key as the browser sent it. Marta now gets Polish. But browsers do not send a language. They send a preference list. Marta’s browser sends pl-PL,pl;q=0.9,en;q=0.8, and another Polish reader in Frankfurt sends pl,en-US;q=0.7,en;q=0.3. Both want the Polish page, and they now have two keys, so each misses. A PoP sees many such strings, and every one is a separate copy of a page the shop publishes in four languages. The cache fills with duplicates and the hit ratio falls.
It also does not stop the attacker. The attacker sends en-US,en;q=0.9, the most common English string, with the poisoned host header. The next reader in Frankfurt whose browser sends that string gets the attacker’s page, because the key still ignores X-Forwarded-Host.
The fix works on the key and on the request together. First, the PoP turns the header into one of the shop’s own languages before it looks anything up: English, German, Polish or French. Marta’s string and the other Polish reader’s string both become pl. The key is the hostname, the path and that one value, and the PoP sends the origin that single value in place of the reader’s string. Marta and the other Polish reader now share one Polish copy.
Second, for anything it may cache, the PoP sends the origin only the headers the key holds. It adds a short list the service allows, such as the reader’s IP address for logging. Nothing on that list may change the page. If the shop prices by the reader’s country, the country belongs in the key, turned into one of the shop’s own values like the language. Requests for pages that are never cached, such as a signed-in basket, go to the origin whole. It sets X-Forwarded-Host itself, to the service’s hostname. The attacker’s header never reaches the origin, so there is nothing to poison. So the rule is that everything the origin reads must either be part of the key or never reach the origin.
The same rule covers query strings. A PoP may sort the parameters if the origin ignores their order. It may drop ones the service lists as meaningless, such as tracking tags, from the key and from the request it forwards. It must never drop a parameter the origin uses, or two different pages share one key. A service’s rules say which paths may be cached at all. Responses meant for one person are never stored: a response with Set-Cookie, or marked private, goes straight to the reader.
Paid files raise a related question. A course video may be cached once and sent to many paying viewers, with a signed URL proving each viewer may see it. The signature must not be in the cache key, or every viewer gets a separate copy of the same video. So the PoP checks the signature and its expiry on every request, hits included, before it looks anything up. Leaving the signature out of the key is safe only because that check runs every time.
The experiment sends five requests for the product page to Frankfurt, one after another, starting with the attacker’s, so the attacker reaches the empty key first. The tabs are a key of the URL alone, the URL with the raw language header, and the URL with a normalized language, forwarding only what the key holds.
The interactive version of this example is available when JavaScript loads.
The gap: Every input the origin reads either belongs in the key or must never reach the origin.
Option 1: The URL alone
Key on the hostname and the path.
Works when: The origin’s response depends only on the URL.
Breaks when: Every reader gets whatever the first request filled: the wrong language, or the attacker’s script.
Option 2: The URL and raw headers
Add each header the origin varies on, as the browser sent it.
Works when: The header has a handful of possible values.
Breaks when: Two readers wanting Polish get two copies, and a header outside the key still poisons.
Option 3: A normalized key, and forward only what it holds (start here)
Turn each header into one of the service’s own values, key on that, and send the origin nothing else.
Works when: Always.
Watch for: A parameter the origin needs but the key drops breaks pages, so test the key against the origin whenever either changes.
In the interview: Open with Marta’s German page, then the attacker’s header, because the second is the same bug with worse intent. Give raw Vary and show both of its failures. Then state the rule: what the origin reads is in the key, or never reaches the origin.
Say this: The cache key holds exactly what the origin uses to build the response, normalized to the service’s own values: the hostname, the path, the parameters that matter, and the language as one of four codes. The PoP forwards only those to the origin and sets proxy headers itself, so an input outside the key cannot poison a shared copy. Responses for one person are never stored, and signed URLs are checked on every request, hits included.
The interactive version of this example is available when JavaScript loads.
The code has three tabs: building the cache key, refusing a fetched copy if a purge landed while it was on its way, and applying the purge log with its heartbeat.
If they ask: where do the PoPs go, and how many?
The internet is not one network. Readers reach it through thousands of providers, and the path between two providers is often longer than the map suggests. Akamai’s 2010 paper on its own network says “even the largest network has only about 5% of Internet access traffic”. It takes “well over 650 networks to reach 90%” (Nygren et al.). So there are two strategies. Build large PoPs at the exchange points where many providers meet, as this design does, or put small clusters of servers inside the providers themselves. Netflix’s Open Connect does the second, with appliances embedded in “over a thousand ISPs” (Netflix).
More PoPs is not free. Every PoP added splits the same readers into smaller groups, so each PoP sees less of every file. The quiet files then stop staying cached, as the launch deep dive worked out. More PoPs make readers closer and each cache colder. The tiers are what make many small PoPs affordable. A good answer places a PoP where readers are far from any existing one, and sizes it with spare room for a failed neighbour’s share.
If they ask: a change that breaks every PoP at once
Anycast makes one mistake dangerous in a new way. The routes are the product, so a bad change to what PoPs announce fails everywhere at once. On 14 July 2025, a configuration error at Cloudflare reduced the locations serving its public DNS resolver’s addresses to “a single, offline location”. That triggered “the global and immediate withdrawal” of those addresses. The outage lasted 62 minutes (Cloudflare).
So configuration rolls out like code. Every change is a new version. It goes to one PoP first, then a few, then a region, and each step waits for that PoP’s own health checks before the next. A change that would stop more than a small share of PoPs announcing a block is refused unless a person confirms it. And every PoP keeps its last good version, so rolling back is one step.
If they ask: the origin goes down
At 18:30 the shop’s origin stops answering. Every fresh copy keeps being served, because a fresh copy never asks the origin. The trouble is copies that expire during the outage. With stale-if-error, the origin says in advance how long a stale copy may still be served when it cannot be refreshed, say a day. Its RFC says that when an error is encountered, “a cached stale response MAY be used” (RFC 5861). The PoP keeps showing the last good page and retries the origin in the background, one request per file. It is the customer’s choice, because some pages are worse stale than missing. A price page may be one of them.
If they ask: a 20 GB game download
A 20 GB file is not stored or fetched as one object. Readers ask for pieces with range requests, and a download that breaks resumes from where it stopped. The PoP stores the file in pieces of, say, 2 MB, each keyed by the file’s version and its position, and fetches only the pieces readers ask for. Every piece must come from the same version of the file. So a fetch sends the version’s ETag in an If-Range header, which needs an ETag that changes whenever a single byte does. If the file changed, the origin answers with the new version instead of the piece. The PoP stops that transfer, drops the pieces it holds for the old version, and starts fetching pieces of the new one.
If they ask: HTTPS for a million hostnames
Every PoP must finish TLS for every customer’s hostname, so every PoP needs the right certificate for each. The browser names the hostname it wants at the start of the handshake, a field called SNI, and the PoP picks the matching certificate. Certificates are issued automatically, through ACME for example, when a customer proves they control the hostname, and renewed long before they expire. The private keys are the most sensitive thing a CDN holds. Some CDNs keep them off the PoPs entirely and ask a key server to sign each handshake. TLS explains the handshake.
If they ask: a flood of requests
Anycast spreads a flood over every PoP that announces the address, so no single building takes all of it. That holds as long as the attackers are spread out, as botnets usually are. A flood of requests for cached files is served from cache, which is what a CDN is good at. The dangerous flood is one that misses on purpose, for example with a random query string on every request, so each one goes to the origin. One defence is the key rule from the poisoning deep dive, which drops parameters the service does not use. The other is a limit on how fast each service’s misses may reach its origin. Load shedding at the edge covers refusing work cheaply.
If they ask: other ways a cache serves the wrong copy
At 17:59:59 a reader guesses the product URL a second early and gets a 404. If the CDN keeps errors for five minutes, everyone sees “not found” until 18:05. So errors get short lifetimes of their own.
Say a rule caches anything whose path ends in .css. A request for /account/profile.css reaches a signed-in page whose server ignores the extension, and the page is cached. The next reader gets someone else’s account. This is called web cache deception. The fix is to cache by what the origin’s headers say, never by how a URL looks.
A page sent both compressed and uncompressed needs the encoding in its key too, reduced to a short list of values like the language. And a change to what a key holds needs new keys, so that copies stored under the old rule are never read by the new one.
Walk one request through the final design
At 18:00 Marta opens shop.example. The CDN’s DNS gives shop.example an address in block A. Routers send her packets to the nearest PoP announcing block A, Frankfurt, whose servers announce it only while their own health checks pass.
Frankfurt finishes the TLS handshake with the shop’s certificate. A server builds the key from the hostname, the path and her language, normalized to pl, and finds the owner on the ring. The owner misses, because the page is new. It collapses every Frankfurt request for the page into one fetch. That fetch goes to the regional tier and then to the shield, which fetches the page once from Virginia for the whole network. The fetch records the last purge entry Frankfurt had applied when it began, and no entry since names the page or its tags, so the copy is stored. Marta sees the page, and a log line records a miss.
At 18:07 Oskar purges the tag product-4411. Entry 8,812 reaches 149 PoPs within a second. Lisbon, cut off, revalidates everything after 10 seconds of silence, then replays the log when its link returns. Marta reloads and sees €130.
The interactive version of this example is available when JavaScript loads.
| Requirement | Where it is met | The trade-off |
|---|---|---|
| FR1: serve from a nearby PoP | Anycast to the nearest PoP, consistent hashing to one owner | A long download breaks when its route changes |
| FR2: fetch misses from the origin | Collapsing per owner, regional tiers, one shield | An extra hop on each miss |
| FR3 and FR4: configure and purge | Versioned configuration; a numbered purge log with a heartbeat and a check on fetches in flight | A cut-off PoP revalidates everything for a while |
| FR5: logs and statistics | A line per request, streamed and counted | A pipeline sized for every request |
| A PoP dies, readers move in seconds | Health-driven announcements, two address blocks, spare room per PoP | Idle capacity in every PoP |
| The origin sees a small share | Owners, tiers and a shield, collapsing at each level | The shield needs a stand-in |
| No reader changes another’s page | A normalized key, and only keyed headers forwarded | Every new header the origin reads must be added to the key |
How does the answer change for Cloudflare, an image CDN or a video CDN?
| Interview variant | What carries over | What changes |
|---|---|---|
| Design Cloudflare, Akamai or CloudFront | Everything on this page | The same problem; ask whether edge code, firewall rules or DNS hosting are in scope |
| Design an image CDN | PoPs, keys, tiers, purges | Images are resized on request, so size and format join the key, and the resizing workers need their own limits |
| Design a video CDN | Tiers, ranges, anycast | Short segments and playlists instead of pages, and bytes dominate; the video streaming breakdown covers the rest |
| Design a global load balancer | The routing deep dive | Nothing is cached; the question is only where each request goes and what happens when a region fails |
| Design a distributed cache | Consistent hashing, hot keys | One data centre, no routing and no origin far away; it is a different problem with a shared tool |
| Design a static site host | Versioned file names, purges | A deploy is a new version of every file, switched in one step, so purges are rare |
What should an answer reach at each level?
| Level | What the answer shows |
|---|---|
| Intern or mid-level | Draws PoPs, a cache and an origin, explains hits, misses and lifetimes, and uses DNS to send readers to a nearby PoP. |
| Senior | Uses anycast and knows it moves readers in seconds, hashes URLs to one owner per PoP with consistent hashing, collapses misses and adds tiers and a shield. Designs purges that reach every PoP, and keys that hold what the origin reads. |
| Staff | Explains why anycast fails differently from DNS, ties announcements to server health and splits address blocks for capacity. Makes purges a numbered log that every cache applies, with a heartbeat and a check on fetches in flight, and closes cache poisoning by forwarding only what the key holds. |
| Principal | Decides where to build PoPs and how much spare room each keeps, what a purge promises customers, how configuration changes roll out without a global outage, and what the CDN does when its control plane is down. |
Test yourself with the quiz, then pick another problem from the System Design interview breakdowns.
By GOAT Engineer. Back to all breakdowns. Privacy Policy · Contact.