Design Netflix / Video Streaming
hardTen million people press play at 8pm. Each one needs a steady stream of video for the next two hours, and any interruption is obvious.
Key Concepts
High-level design
Ingest: master upload → object store (S3) → transcoding job.
Transcode: distributed workers consume Kafka jobs; produce bitrate ladder × codecs × HLS/DASH segments.
Distribute: segments pushed to CDN (Open Connect in-house, or commercial).
Playback: client fetches manifest → ABR algorithm picks bitrate → fetches segments → plays.
Recommendations: nightly batch (Spark) + online reranker.
Telemetry: client → Kafka → analytics + encoding optimization.
DRM: key server with per-session licenses.
Components
- Upload service + object store.
- Transcoding cluster (Kafka job queue, encoder workers).
- Manifest service (per-title, per-region rules).
- CDN (push or pull with origin shield).
- Playback client + ABR algorithm.
- DRM license server.
- Recommendation pipeline (batch + online).
- Telemetry pipeline (start/stop/rebuffer/quality switch events).
- Geo / DRM enforcement layer.
Bandwidth and storage, worked
Concurrent streams at peak 10,000,000
Bitrate, 1080p 5 Mbps
-------------------------------------------------------------
Aggregate egress 10M x 5 Mbps = 50 Tbps
If 20% watch 4K at 20 Mbps
8M x 5 Mbps + 2M x 20 Mbps = 80 Tbps A 100 Gbps edge appliance serves
100 Gbps / 5 Mbps = 20,000 streams
Appliances for 10M streams = 500
(before redundancy, and before the 4K mix above) Catalogue storage, one full copy
Titles 100,000
Ladder per title (all renditions, all codecs) ~100 GB
100,000 x 100 GB = 10 PB Edge site, head of the distribution
Titles covering ~90% of regional views ~2,000
2,000 x 100 GB = 200 TB
(fits an appliance) Segment count for one 2-hour title
Renditions x codecs 10 x 3 = 30
Segments at 4 s (7,200 / 4) = 1,800
Files 30 x 1,800 = 54,000Consequences:
- 50 Tbps is why appliances sit inside ISPs; transit at that volume is
the dominant cost of the business.
- 10 PB for one copy is why edges hold the head, not the catalogue.
- 54,000 files per title is why the transcode pipeline and object naming
scheme get design attention that the "app" never needs.
Why pre-position instead of cache
Demand-filled cache, new release at 00:00
First viewer per edge: miss -> origin fetch.
500 edges x 30 renditions = 15,000 origin fetches
...in the first seconds, all for the same title, while the whole
audience waits on the slowest of them. Pre-positioned, pushed overnight
Origin fetches at release time 0
First viewer is served from local storage. What decides placement
- Predicted popularity per region (past viewing of similar titles,
pre-release engagement).
- Language and subtitle demand: a title's Hindi audio track belongs in
some regions and not others.
- Appliance free space: eviction is by predicted future views, not by
recency, because recency is a poor predictor on a release schedule. What still needs demand-filling
The long tail. A 2009 documentary watched twice a month per region is
not worth pushing; it comes from a regional cache on request, and the
extra 40 ms of start-up is invisible next to the player's own buffering.Failure modes in production
Bitrate oscillation
Symptom: quality flips every few seconds; viewers report flicker.
Cause: the player upgrades on a brief throughput spike, then starves.
Fix: hysteresis -- require sustained headroom and a minimum buffer
before stepping up; step down immediately.
Premiere thundering herd on the long tail
Symptom: a surprise hit that was not pre-positioned saturates regional
caches.
Cause: placement driven only by predicted popularity.
Fix: real-time promotion -- when an unplaced title crosses a request
threshold, push it to edges mid-event rather than serving every miss
from origin. Appliance disk failure during peak
Symptom: one ISP's subscribers see buffering while the rest are fine.
Cause: single copy of the head at that site.
Fix: two appliances per site with overlapping heads, and failover to
the regional cache rather than to origin. Codec mismatch on old devices
Symptom: playback fails silently on a subset of TVs.
Cause: manifest advertises a rendition the device cannot decode.
Fix: device capability negotiation before manifest generation, and keep
an H.264 rung in the ladder long after it is inefficient.