40. Design Video Upload and Streaming (YouTube)
1
The interview prompt2
40.1 What do you ask first?3
40.2 How big is this, really?4
40.3 What are the doors?5
40.4 What do we store?6
40.5 What does the whole system look like?7
40.6 How does the upload pipeline work?8
40.7 How does transcoding work?9
40.8 How does adaptive bitrate work?10
40.9 How does CDN delivery work at this scale?11
40.10 How do you count views?12
40.11 What would you say in the last five minutes?13
Score yourself14
Variations to practise15
Sources16
Code lab40. Design Video Upload and Streaming (YouTube)
40.8 How does adaptive bitrate work?
3 min read+10 XP
The player, not the server, decides quality (Chapter 26):
- It downloads the master playlist listing every quality, then fetches segments one at a time.
- For each segment, it picks the highest quality that fits its measured throughput with a safety margin, and plays it safe when its buffer is low.
Figure: viewers forgive a softer picture; they leave on stalls.
In the chapter's code, a 4-minute video over a connection that swings between 1.5 and 10 Mbit/s stalls for 144 seconds if it always plays 1080p, and about 10 seconds with a simple buffer-aware adaptive player, at an average of about 2.9 Mbit/s.
Tricks real players use:
- Start low for a fast first frame, then climb.
- Shorter segments (2-4 s) react faster but mean more requests; 6 s is a common target for on-demand video (Chapter 26).
- Prefetch the first segments of the next likely video.
Memory code: "Measure, check the buffer, pick the best that fits, and never let it stall."