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
Upload a video
Encode the ladder
Press play
Segment miss
Count a view
A worker dies
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
The numbers, at a glance
1 from the origin99 from the edge and shield
320 PBY1
640 PBY2
960 PBY3
1.3 EBY4
1.6 EBY5
57% originals43% renditions
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.
GET abc.mp4
5 Mbit/s for everyone
3G viewer stalls
+ One encode, one file.− One bitrate: slow links stall.
GET ?kbps=1800
encode now
7M viewers × CPU
+ Any bitrate.− CPU on every play; nothing cacheable.
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.
Player
App server
File serversDatabase
Player
API serversTranscode queue
Transcode workers
Object storageMetadata DB
Player
CDN edgeAPI servers
Transcode queueTranscode workers
Object storageMetadata DB
Player
CDN edgeAPI servers
Origin shieldMetadata cacheView counter
Object storageSharded metadata
Was this walkthrough useful?Your vote tells us what to improve next.