FullStack AI Hub
Studio
System Design · 02. Scaling
10 min
10 steps
Beginner

Content Delivery Networks

Serve assets from global edge PoPs, collapse cache misses with an Origin Shield, and invalidate safely.

System Design02. ScalingLesson 4 of 5
10 minBeginner10 steps

Content Delivery Networks

Serve assets from global edge PoPs, collapse cache misses with an Origin Shield, and invalidate safely.

GLOBAL REQ/S
6,000/s
APAC P95 RTT
240 ms
ORIGIN LOAD
94% HOT
EDGE OFFLOAD
0%
35 ms120 ms220 msUS UsersEU UsersTokyo UsersUS-EastOrigin94%100% egress!
edge hit
origin miss / media
purge / push
origin overload
In This LessonStep 1 of 10
What You Will Master
  • ✓Slash cross-ocean latency by serving static and cacheable assets from regional Edge PoPs
  • ✓Prevent multi-PoP cache-miss storms from crushing origin using an Origin Shield tier
  • ✓Update assets safely using content-hashed immutable URLs and stale-while-revalidate headers
  • ✓Choose between Pull CDNs, Push CDNs, and edge compute for dynamic personalization

Architectural Trade-Off Comparison Matrix

PatternBest ForKey Trade-Off
Pull CDN (Cache-on-First-Miss)Web assets, images, JS/CSS bundles, and public API responses with Zipfian hot popularityFirst visitor in each PoP pays a cold-miss round-trip to origin until cached
Push CDN (Pre-Warm Edge)Large software releases, video premieres, and rarely updated static media packagesConsumes edge storage even for unpopular files and complicates deployment pipelines
Origin Shield (Mid-Tier Cache)Global fleets with 50+ PoPs where simultaneous TTL expiries would hammer origin 50×Adds one small (~10 ms) intermediate hop on a true cold miss in exchange for 95%+ origin offload
Content-Hashed URLs + Long TTLImmutable JS/CSS/images (`app.9f3a2c.js`) with `max-age=31536000, immutable`Requires build-pipeline asset fingerprinting; HTML shell must still stay short-TTL

Step-by-Step Architectural Breakdown (10 Steps)

Full architectural walkthrough transcript and state transitions for Content Delivery Networks.

STEP 01 · PROBLEMJump to step →

Serving global users from a single origin hurts

Your product launches globally, yet all images, fonts, and JS bundles still come from one **US-East Origin** datacenter. Speed of light through fiber is unforgiving: a shopper in **Tokyo** pays **220 ms** per round-trip before a single image byte renders.

Worse, every browser download burns your origin’s expensive egress bandwidth and saturates web servers serving identical static files over and over.

watch:No amount of CPU tuning fixes speed-of-light physics—to cut a 220 ms ocean round-trip down to 18 ms, bytes must live near the user.

Speed-of-Light RTTOrigin Egress CostStatic Bottleneck
STEP 02 · SOLUTIONJump to step →

Place Regional Edge PoPs close to every user

We front our domain with a **Content Delivery Network (CDN)** operating **Points of Presence (PoPs)** inside major cities worldwide. BGP **Anycast** routes each browser automatically to the nearest PoP.

With a **94% edge cache hit ratio**, Tokyo shoppers fetch images locally in **18 ms** instead of 240 ms, and Origin load plummets from **94% down to 8%**.

good:Edge PoPs also terminate TLS right next to the user—saving 200+ ms on the TCP + TLS handshake before any HTTP payload even transfers.

Edge PoPAnycast RoutingEdge TLS Termination
STEP 03 · TRADE-OFFJump to step →

Pull CDN vs Push CDN

In a **Pull CDN** (most common), the edge fetches an asset from Origin lazily on the **first cache miss** and caches it until its `Cache-Control` TTL expires. Zero upload scripts needed.

In a **Push CDN**, your CI pipeline proactively pushes large releases (like a 2 GB game patch or video launch) to every PoP *before* users arrive—avoiding cold-miss lag at the cost of extra storage and push ops.

idea:Default to Pull CDN for 95% of web workloads; reserve Push pre-warming for massive scheduled launches where cold-start latency would hurt.

Pull CDNPush CDNEdge Pre-Warming
STEP 04 · TECHNIQUEJump to step →

Control edge vs browser freshness with Cache-Control

CDNs do not guess how long to store responses—they obey HTTP headers. Setting `Cache-Control: public, max-age=60, s-maxage=3600` tells **browsers** to cache for 60 seconds while **shared CDN PoPs** cache for a full hour.

Splitting `max-age` (browser) and `s-maxage` (CDN) gives you instant global purge control at the edge without getting stuck waiting for millions of user browsers to expire.

good:Never send `Cache-Control: public` on personalized HTML containing user cookies or auth data—use `private, no-store` for private API responses!

Cache-Controls-maxage vs max-ageVary Header
STEP 05 · PROBLEMJump to step →

When 50 PoPs miss at once: the Origin Storm

A CDN with 50+ global PoPs introduces a surprising failure mode: when a hot homepage or viral product image expires (or after a global cache purge), **every single PoP** misses independently and fetches from Origin simultaneously!

Instead of 1 origin refill, your Origin gets slammed by **50× concurrent duplicate fetches**—pinning CPU to 97% and cascading 504 timeouts back to every continent.

watch:More edge PoPs means lower latency for users, but a higher cache-miss fan-in multiplier against your Origin.

Origin Thundering HerdMulti-PoP Miss AmplificationGlobal Purge Risk
STEP 06 · SOLUTIONJump to step →

Collapse duplicate misses with an Origin Shield

We insert a centralized **Origin Shield** (mid-tier cache) right in front of our Origin datacenter. Now when 50 global PoPs miss on the exact same viral asset, they all query the **Origin Shield**—not Origin.

The Origin Shield collapses concurrent requests (**request coalescing**), fetches the asset from Origin **once**, and serves the other 49 PoPs straight out of Shield RAM. Origin CPU plunges from 97% down to **12%**!

idea:An Origin Shield turns an O(number_of_PoPs) miss fan-in into O(1)—a must-have for any global CDN deployment.

Origin ShieldTiered CachingRequest Coalescing
STEP 07 · TECHNIQUEJump to step →

Skip slow purges with content-hashed URLs

Explicitly purging an old file (`app.js`) across 200 global PoPs is slow, error-prone, and still leaves stale copies trapped in user browsers.

Instead, embed a content hash in every filename (`app.9f3a2c.js`) and set `Cache-Control: max-age=31536000, immutable`. When you deploy `v2`, HTML points to `app.7b1e09.js`—instant global rollout with **zero cache invalidation**!

good:Cache-bust via content-hashed filenames for JS/CSS/images; reserve active CDN purge APIs only for dynamic HTML or emergency takedowns.

Asset FingerprintingImmutable CachingCache Busting
STEP 08 · TECHNIQUEJump to step →

Zero-wait refreshes with Stale-While-Revalidate

For semi-dynamic pages (product listings, news feeds) with a 60-second TTL, the unlucky visitor who arrives at second 61 normally blocks waiting for Origin to regenerate the page.

Adding `stale-while-revalidate=300` lets the Edge PoP serve the **61-second-old cached copy instantly in 14 ms** while quietly refreshing from Origin in the background—plus `stale-if-error=86400` keeps the site online even if Origin crashes!

idea:Pairing `stale-while-revalidate` with `stale-if-error` turns your CDN into both a latency accelerator and an outage survival shield.

stale-while-revalidatestale-if-errorBackground Refresh
STEP 09 · TECHNIQUEJump to step →

Push auth, A/B routing & redirects to Edge Workers

Modern CDNs go beyond static files: lightweight **Edge Workers** (V8 isolates / WebAssembly) run in < 1 ms at every PoP to verify JWTs, pick A/B experiment buckets, localize currency, and block bots *before* traffic crosses the ocean.

Static assets and cached HTML serve right from the PoP, while only genuine dynamic writes (like checkout) travel back to Origin.

idea:Keep Edge Workers lightweight and stateless—avoid heavy database joins across oceans inside an edge function.

Edge FunctionsV8 IsolatesEdge Bot & WAF Filtering
STEP 10 · RECAPJump to step →

Content Delivery Networks recap

A production CDN stack layers **Anycast Regional Edge PoPs** for sub-25 ms global delivery, an **Origin Shield** to collapse multi-PoP cache misses into a single origin fetch, and **content-hashed immutable URLs** plus `stale-while-revalidate` so updates stay instant and outage-proof.

Test killing a PoP or surging traffic below to confirm the Origin stays calmly protected.

good:Checklist: Anycast PoPs + Origin Shield + content-hashed immutable assets + s-maxage/SWR headers + WAF at the edge.

Global Edge StackCDN Production Checklist

Related Production Deep-Dives & Simulators

Related Systems Course
Free · Verifiable Credential

FS-201Production LLM Engineer

Design an observable full-stack LLM product from capability validation through interfaces retrieval evaluation security and operations.

37 concepts~35h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.