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.10 How do you count views?
3 min read+10 XP
A view count must be cheap (billions of events a day), roughly live, and hard to inflate:
- The player sends a view event after meaningful watching (the chapter's code uses an assumed 30 seconds).
- De-duplicate per viewer and video within a window: refreshing the page shouldn't add views. In the chapter's code, a refresh within 30 minutes and a 5-second watch are not counted; a return after the window is.
- Count in sharded counters (many small counters per hot video, Chapter 13's hot keys), flushed to the stored total every few seconds or minutes.
- Run fraud detection asynchronously (bots, click farms) and subtract invalid views later; the public count can lag.
- Exact numbers for creator payouts come from a separate, audited pipeline over the event log, like Chapter 35's final job.
Memory code: "Count real watches once per viewer, in shards, and audit the money later."