System design · Edge caching and the launch stampede

How to design Netflix's video delivery (CDN)

Serve almost every video byte from caches close to viewers, fill those caches ahead of demand, and let the origin see only the rare miss. 10 million concurrent viewers at 5 Mbit/s is 50 Tbit/s of egress, which no central data centre can send.

Updated · 4 min read

A teaching design of a system like Netflix, not Netflix's real architecture.

The player gets a manifest from the control plane, then fetches segments from the nearest edge cache inside its ISP. Misses go to a regional origin shield, then origin.

Netflix CDN architecture diagram

The player gets a manifest from the control plane, then fetches segments from the nearest edge cache inside its ISP. Misses go to a regional origin shield, then origin.

The short version

  • 10 million viewers at 5 Mbit/s is 50 Tbit/s. No central data centre can push that, so bytes come from caches near viewers.
  • Video is split into small immutable segments listed in a manifest, which cache perfectly at the edge.
  • The control plane returns a manifest pointing at the best edge. The CDN is the data plane.
  • A launch starts with cold caches, and every first miss hits origin at once. Pre-position, shield, coalesce and jitter TTLs.
  • Hit ratio is the lever: 70% to 95% cuts origin's share from 30% to 5%.

Run it: click the fixes, watch the numbers

Live simulationFailing

Scroll the diagram to see every component at a readable size.

no cdnUsers20,000 req/sAPI Server×820,000 req/scapacity 8,000 req/sCache8,000 req/scapacity 100,000 req/sDatabase×4800 req/sreads 3,000 · writes 1,000 req/s
p99 latency
-
Errors
100.0%
Cost
$1,348/mo

The API tier can serve 8,000 req/s but is receiving 20,000. 100% of requests fail. More API servers behind a load balancer would share the load.

Real simulator engine, not an animation.Edit in the playgroundTake the cache stampede challenge
Embed this simulation in your blog, docs or course

Free to embed. Paste this HTML anywhere that accepts an iframe.

Clarifying questions to ask first

  • Video delivery only? (Assume yes. Recommendations, billing and the upload pipeline are out.)
  • How many viewers at peak, at what quality? (Assume 10 million concurrent at about 5 Mbit/s HD.)
  • How big is the catalogue? (Assume 10,000 titles, each in about 20 encodings.)
  • What counts as good playback, and do launches concentrate viewers? (Start-up in a couple of seconds, very little rebuffering. Assume a large share press play on a new title in the same hour.)

Numbers that shape the design

QuantityAssumptionResult
Concurrent viewers at peak10 million-
Average bitrate5 Mbit/s (HD)10M × 5 Mbit/s = 50 Tbit/s of egress
Catalogue10,000 titles × 20 encodings × 5 GB≈ 1 PB of encoded video
One origin server≈ 40 Gbit/s of egress> 1,000 servers if every byte came from origin

The origin should see only a small fraction of requests.

How video is served

Each title is encoded into a ladder of resolutions and bitrates, each split into segments a few seconds long. The player fetches a manifest (HLS or DASH), then downloads segments over plain HTTP. With adaptive bitrate it measures throughput and picks the next segment's quality, so a slow connection drops quality instead of stalling. Segments are immutable, so edges cache them with long TTLs.

High-level design

The control plane (API servers in a cloud region) handles login, browsing and "play", and returns a manifest whose segment URLs point at the best edge for that viewer. The data plane is the CDN: edge servers inside ISPs and internet exchange points. On a miss, the edge asks a regional cache or origin shield, and only then origin storage. Netflix runs its own CDN, Open Connect, with cache appliances inside ISP networks; many other services use commercial CDNs.

Where it breaks: the cold-cache stampede

A cache only protects origin when it already holds the content. At a launch the edges are cold, so every viewer's first request misses at the same moment. In the simulation above, a cold CDN sends the full 20,000 requests per second to an API tier that serves 8,000, and 60% fail. A cache flush, a deploy that changes cache keys, or a hot object expiring everywhere at once does the same.

Preventing the stampede

  • Pre-position: push a title to edges off-peak before launch, based on predicted popularity. Open Connect fills its appliances this way.
  • Origin shield: a regional tier between edges and origin turns a thousand edge misses for one segment into one origin request.
  • Request coalescing: when many requests miss on one object, one fetches it and the rest wait.
  • TTL jitter, so hot objects don't all expire at once, and multiple CDNs with steering when one is overloaded.

Hit ratio is the lever

At a 70% hit ratio origin serves 30% of requests; at 95% it serves 5%, six times less. Viewing is concentrated on a small share of popular titles, which makes very high hit ratios achievable. In the simulation, pre-warming from 70% to 95% cuts origin traffic from 6,000 to 1,000 requests per second.

Common traps

  • Sizing the catalogue as one file per title. Count the whole rendition ladder for storage and cache fills.
  • Downloading the whole film before adapting quality. The player needs separately addressable segments to switch rendition mid-play.
  • Replacing bytes at a long-cached segment URL. Edges keep the old object; publish immutable versioned names.
  • Treating a nearby cloud region as a nearby delivery edge. Viewers are reached through ISP and exchange-point caches, a separate path from the API region.

Follow-up questions interviewers ask

  • "Why not just add more origin servers?" At 50 Tbit/s you'd need over 1,000, and every byte would still travel far. Edges cut both server count and distance.
  • "What happens when a hot segment expires everywhere at once?" Every edge misses together. Jitter TTLs and coalesce concurrent misses.
  • "Which titles do you pre-position?" Those predicted to be popular. Viewing is concentrated, so that covers most requests.

Frequently asked questions

What is a cache stampede or thundering herd?

+

Many requests miss the cache at once, after a cold start, a flush or a simultaneous expiry, and all hit origin together. Pre-warming, request coalescing, origin shields and TTL jitter prevent it.

What is origin shield?

+

An extra caching layer between edge servers and origin that collapses many edge misses for one object into a single origin request.

What is adaptive bitrate streaming?

+

Video is encoded at several bitrates in short segments. The player picks each next segment's bitrate from its measured download speed, so playback drops quality instead of stalling.

Does Netflix use a CDN?

+

Yes, its own, called Open Connect, with cache appliances inside ISPs and at internet exchange points. Popular content is pushed to them ahead of demand.

Now fix it yourself.

Open the failing Netflix CDN design in the playground and make it hold. No signup.