Ch.62: CDN System Design: Fast Edges, Overloaded Origin.

Outline

Transcript

0:00 A software publisher wants downloads to start quickly worldwide. A content delivery network, or CDN, serves its files through nearby locations, instead of sending every user to the publisher's original server. We'll design that delivery service: how a download reaches a healthy location, gets the correct bytes and avoids overloading the source when those locations have no stored copy yet. Because being close to the user doesn't mean that server already has the new release. Yeah. Publish a new version everywhere, and all those conveniently nearby servers can ask the same distant source for their first copy. That first-copy problem opens a complete design question.

0:39 Follow one download: name lookup sends the user to an edge, a nearby serving location. It checks whose file was requested before using stored bytes. Missing bytes go through shared upstream caches, then an origin-facing fill gateway that budgets reads from the origin, the publisher's source server. Customer configuration separately tells those components what to serve. We'll return to this same map with the failure paths explained. First, what can the publisher actually ask this service to do? With those publisher operations, our functional requirements are clear.

1:11 First, a publisher registers a domain it controls and the origin serving its files. Second, users can fetch a particular artifact version. 3rd, an interrupted download can request the remaining bytes. 4th, the publisher can change delivery policy or invalidate a stored response. 5th, keep customers separate. Another publisher might use the same path name; that mustn't select our customer's file or source server. For example, both customers can publish a current release. The domain must tell us whose artifact the request means.

1:41 Yup. Private account responses aren't public downloads either. Our first product proxies those without putting their bodies into shared cache storage. With those operations defined, add non-functional requirements: prompt first bytes, correct completed downloads and availability when a location fails, plus tenant isolation and finite origin bandwidth. A download that begins instantly and stalls halfway through still disappoints the user. So measure completion too, not just the first response. For a capacity exercise, suppose we have 200 edge locations and a new 100-mebibyte artifact. That's our invented workload, not a provider benchmark.

2:16 The source has to feed the first copies somehow. Putting the word global on the diagram hasn't increased its network connection. Exactly. Fetching missing bytes into a cache is called a fill. We'll budget those transfers shortly. First, how does this download know which customer's source to use? That customer-source choice leads to our configuration API, the control path. A publisher submits its mapping there. We authenticate the change and verify domain ownership before distributing versioned settings to edges.

2:46 What does an edge do if that configuration service disappears while somebody's downloading? It can keep using its last accepted public configuration. The serving path shouldn't consult the central configuration database for every block of a file. Agreed. But a brand-new domain with no accepted mapping can't borrow whatever origin happens to answer. Reject the unknown mapping. Yes, and expose which locations accepted the change. If this publisher points downloads at a new origin, a database write alone doesn't prove the serving network has switched.

3:18 I would keep that continuity promise separate from emergency revocation. An edge isolated from updates could still use the old public mapping. That's the limit of our choice: an existing download can continue, but we can't call a new restriction globally effective until the network has adopted it. Now route users for that accepted domain. One option is DNS steering: name lookup returns an address for a suitable edge, using network performance and health. AWS's CloudFront docs describe that route.

3:48 Cloudflare documents a different approach, anycast, where multiple locations announce the same address and network routing chooses the path. So neither architecture means we draw a circle around the geographically closest building and declare the routing problem solved. Nope. A nearby location can be overloaded or unreachable. And changing where new connections go doesn't move an existing connection or copy files to the replacement. The empty replacement is easy to miss when the failover arrow looks so reassuring.

4:16 The public docs and standards are linked in the description. Once a request reaches that edge, we still have to decide whose bytes it's allowed to receive. Once routing reaches an edge, bind the requested domain to its customer before looking in shared storage. The pathname alone doesn't identify the file. Then identify the representation, meaning the particular response bytes. For instance, compressed and uncompressed responses can share a URL but have different contents. Would you include every request header in the key, just to avoid accidentally merging different responses?

4:47 Well, that can destroy reuse. The origin's Vary header names request fields that can select different responses. Include those distinctions, and don't discard meaningful query parameters either. Cache eligibility comes before that optimization. Respect no-store and private responses. For this public-artifact service, login traffic bypasses shared storage rather than relying on a cleverer public key. Yeah, a high hit rate would be a disaster if the hit returned somebody else's account page. Correct identity is worth checking before speed.

5:19 Next give that eligible representation storage within the location. A front proxy selects a cache worker; metadata tracks headers and byte intervals actually present on disk. Suppose the worker has only the beginning of a large file. A metadata entry saying present can't mean the whole download is ready. Right. Track completed coverage, and coordinate missing intervals with work already in progress. A failed transfer leaves partial coverage, not permission to serve invented trailing bytes. Sure. A popular artifact can have local replicas, so one storage machine doesn't carry every warm read.

5:54 We don't need every object on every machine. That spreads reads inside a location. Another continent still needs its own first copy. Could all the locations just contact the origin independently? That's certainly a simpler request path. They can, if the origin budget supports it. Let's put the cold-copy numbers against that simpler design before adding another tier. So consider a release using direct origin fills. 200 empty locations each fetch one complete 100-mebibyte object: about 19.5 gibibytes leaving the origin.

6:27 No duplicate download within a location, even. The multiplication comes from having 200 different places to fill. Then show me how to share the origin's work across those locations. All 200 still need the file, so where can the source copies go down? Choose four upper-tier caches, shared upstream locations. An edge asks its upper tier. If that tier lacks the artifact, it fetches one complete copy from the origin and supplies its downstream edges. Ah, then four initial copies cost the origin 400 mebibytes, rather than 20,000. 50 times less source traffic in this simplified burst, without removing any edge's demand.

7:07 Right. The upper tiers supply the other copies. The bytes haven't disappeared; most distribution now uses the delivery network's links and storage. Source copies and delivered copies are different counts. That's what the hierarchy changes, rather than making a global release free. Exactly. AWS Origin Shield and Cloudflare Tiered Cache both illustrate that hierarchy principle. Identical in-flight requests can also share work, when their identity and policy permit it. True, and our arithmetic excludes retries, eviction and different representations.

7:36 It explains the healthy first-fill opportunity, not a 50-times guarantee during every incident. But shared fills get trickier when the client wants only part of an artifact. A byte-range request names the needed interval, instead of asking for everything again. For example, a user loses connection midway through a download and retries at another edge. What keeps their saved half consistent with the missing data? A strong validator is an identifier that matches only when the response bytes are identical. Check it before combining pieces.

8:06 HTTP's caching rules don't permit assembling ranges with different strong validators. So even if the offsets line up, the first half of yesterday's file and the second half of today's file aren't a successful resume. Definitely not. The client's If-Range condition asks for the interval if the version still matches; otherwise, it gets a complete replacement instead of an incompatible continuation. And if the origin ignores the range and sends the full file, our edge can't label that body as though it started halfway through.

8:38 Correct. Preserve the response's actual range and representation. Compressed bytes have their own offsets too; transforming them isn't permission to reuse offsets from another encoding. That range contract leaves a storage choice. We still have to choose how much an upstream fill fetches, even when the client needs just a few bytes. Give me a concrete tradeoff. Why wouldn't we always fetch precisely the missing interval? Small intervals can produce many upstream requests and coordination overhead.

9:06 Larger chunks, fetched along fixed byte boundaries, reduce that work but may transfer bytes the client never uses. So a customer checking the end of an archive could cause a much larger fill. That hurts twice if the excess bytes cross cache tiers. Yeah. Cloudflare's engineering account describes retiring customer-configured range sizes after seeing both problems. Its newer implementation checks which chunks are already cached, then fetches missing coverage along chunk boundaries. Oh, interesting. Did that make the extra bytes disappear?

9:36 No. Picture a request for 1 byte inside a missing chunk. Fetching the containing chunk brings extra bytes too. Their design bounds that overfetch; it doesn't discover a chunk size that's ideal for every workload. Nice. Keep the client response correct while choosing a manageable upstream unit. And partial origin fetching still depends on the origin supporting byte ranges. Those partial copies raise another versioning concern. Keep published artifact bytes fixed at their URL: that's immutable. A new release gets a different address, separate from the small current-release pointer.

10:11 The pointer might say which version to download. It's small and changes often, so it needs its own explicit freshness and revalidation policy. Consider a publisher fixing a broken release. Can we just purge the old pointer and promise everyone switches immediately? Not honestly. Invalidation has to propagate, and a disconnected location may lag. Report acknowledgement and incomplete coverage instead of treating the first accepted purge request as global completion. It's tempting to treat accepted as completed.

10:40 We need the response to distinguish that request from the locations still waiting for the change. And invalidating our stored copies doesn't retract an installer somebody already downloaded. That's outside the delivery service's reach. The immutable URL keeps an in-progress download coherent while the separate pointer tells new clients about the replacement, according to its freshness policy. Now lose an upper tier during the release. Our delivery path needs a secondary, but the replacement might not have that artifact yet.

11:10 My first thought is to send every blocked edge straight to the origin. Doesn't that at least get the downloads moving again? It can also recreate the entire cold burst at once. Take the failed parent's downstream locations: each independently bypassing it removes the sharing we added to protect the source. Wait, so the secondary arrow needs a bandwidth budget, not just an address? Yes. In our proposed service, each upper tier has a configured secondary. Both routes use the same origin-facing fill gateway.

11:40 It admits streams against that customer's budget and paces their bytes, so changing parents doesn't create another allowance. So two replacement fills arrive there. One gets capacity and starts reading; the other waits, rather than deciding that a failed parent permits an emergency shortcut? Exactly. The waiting fill has a bounded deadline. If capacity doesn't open in time, reject it and bound its retries. An unlimited queue would only hide overload until clients time out. But that gateway is now on every origin fetch.

12:10 What happens when it fails? Partition the service by customer origin and replicate it. A replacement must respect the existing allowance, not start a fresh budget while the previous holder might still spend. During uncertainty, block new cold fills. Warm edge reads don't need this gateway. We trade some cold-miss availability for protecting the origin's connection. Otherwise, the failover path defeats the very limit it was meant to preserve. The backup box is green, but its disk is empty. That reassuring arrow still has a real download behind it.

12:42 Yeah. Restoring a route and supplying its missing bytes are different jobs. These controls are our design choices, not claims about every provider's defaults. That refill budget leads to byte measurements. A healthy-looking request hit rate can hide almost all of the source traffic. How can almost every request hit while the origin still does almost all the transferring? Suppose 99 cached responses are 1 kibibyte each, and one missed download is 100 mebibytes. We served 99 requests out of 100 from cache, but that miss dominates payload bytes.

13:17 That dashboard looks excellent while the source link does almost all the work. Exactly. In this made-up example, ignoring headers, the source supplies about 99.9% of payload bytes. So graph origin-fill bytes alongside request hits. Then check byte reuse, waiting fill work and client completion too. A fast first byte followed by a stalled body shouldn't disappear behind the hit-rate average. Yeah, now an operator can distinguish a popular warm release from a few expensive cold reads before adding capacity to the wrong layer.

13:50 With those costs visible, a smaller publisher could reasonably object: our users are regional, our files are small, and the origin handles the misses. Why buy all this hierarchy? They might not need it. Fewer layers can mean less operational work and fewer extra hops. Choose from source capacity and request geography, not from the largest architecture we can draw. I think the decision also depends on shareable traffic. A personalized response can benefit from a nearby proxy without becoming reusable public file bytes.

14:21 Right. And the CDN isn't the durable master copy or a guarantee that the publisher's software is trustworthy. It delivers the chosen representation; storage durability and software authenticity need their own controls. Agreed. Keep only the layers this workload needs. The same network layout won't win for a small regional site and a worldwide artifact release. Finally, trace the complete journey on our original architecture. Customer configuration establishes the domain, origin and serving policy; healthy-edge steering gets the user into the delivery network.

14:54 An eligible warm response comes from local storage. Missing bytes follow the shared fill path, with representation checks keeping a resumed artifact coherent. If an upstream location fails, its secondary still passes through the origin-fill budget. Nearby service helps only when we can supply the right bytes. And the global release no longer means every empty location independently demanding its first copy from the publisher. We can trace both the bytes and the limits that keep them moving. Thanks for listening to Learning Podcasts.