Skip to content
SD-7 · Back to the write-up

Design a Video Streaming

Encode each video once into small segments at 6 bitrates, and let the CDN and shield serve 99% of the bytes while the player picks the bitrate.

Follow a request

Clients
Edge
Services
Data
PlayerPhone, browser, TV
CDN edge95% of bytes
Origin shield80% of misses
API serversPages, URLs, events
Transcode queueEncode tasks
Transcode workersFFmpeg pool
Object storageOriginals + segments
Metadata DB8 shards by video_id
View counterStream + counts
1player → api · GET /videos/abcThe viewer opens a video. The watch page data, with the signed master manifest URL, comes from the metadata cache.1 / 5

The numbers, at a glance

Of every 100 bytes watched……1 reaches the origin
1 from the origin99 from the edge and shield
Video piles up875 TB of new video a day
Originals dominate storage1 GB original vs 750 MB of renditions per video
So originals move to an archive tier after 30 days; they are only read to re-encode.

Press play, in order

Cache and edge hits shown. On an edge miss, the CDN asks the shield, then object storage.

Player
API server
Metadata cache
CDN edge
Origin shield
1 GET /videos/abc
2 get abc:v7
3 row
4 title + signed manifest URL
5 GET master.m3u8
6 6 renditions
7 GET 360p/0.m4s
8 miss (rare)
9 segment
10 first frame
11 GET 720p/1.m4s …
12 events every 30 s
RequestResponseAsync, does not block

What the player downloads

The decision this question is really about.

One MP4
Demo only
GET abc.mp4
5 Mbit/s for everyone
3G viewer stalls
+ One encode, one file.− One bitrate: slow links stall.
Encode per viewer
Far too costly
GET ?kbps=1800
encode now
7M viewers × CPU
+ Any bitrate.− CPU on every play; nothing cacheable.
Segments + ABR
Our pick
master.m3u8
360p720p1080p
4 s segments at the edge
+ Encode once; 95% edge hits.− 6× storage, a pipeline to run.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 1,000 viewersMake it work
Player
App server
File serversDatabase
One server encodes one MP4 and streams it from a file server.
Stage 2 · ≈ 10,000 viewersEncode once
Player
API serversTranscode queue
Transcode workers
Object storageMetadata DB
A queue and worker pool encode 6 renditions as segments; video moves to object storage.
Stage 3 · ≈ 1M viewersServe from the edge
Player
CDN edgeAPI servers
Transcode queueTranscode workers
Object storageMetadata DB
A CDN answers 95% of the bytes from near the viewer.
Stage 4 · ≈ 10M viewersGlobal scale
Player
CDN edgeAPI servers
Origin shieldMetadata cacheView counter
Object storageSharded metadata
A shield for edge misses, a metadata cache, and views counted in a stream.
Was this walkthrough useful?Your vote tells us what to improve next.