Chapter Nineteen · Problem Thirteen

Video Streaming

Other problems reach for a CDN late, if at all. Here the first sum draws it. What stays hard sits behind it: an upload that survives a drop, a ladder of bitrates, and what the least-watched videos cost.

4 lessons · 45 minutes
The Question

"Design a video platform: creators upload videos and millions of viewers watch them on any device."

Elsewhere in this course, a CDN turns up late, as a scaling step, if it turns up at all. Here the order reverses. The first estimate comes to 7 terabits a second, seventy 100-gigabit links, so the edge is in the first design, and everything behind it deals only in misses.

The blocks are ones you have met. Chapter 2's The Edge: CDNs as a Black Box did this very sum and sent it here, and its Stateless Services, Many Copies says where an upload in progress lives. Chapter 6 gives the work queue in Queues, Logs and Pub-Sub, the task delivered twice in Delivery Semantics at Scale, and the alarm on a backlog's age in Backpressure and Load Shedding. Chapter 5's Leases, Locks and Fencing prices a lock whose lapse costs only work. The object store is the box Chapter 1's API and Data Before Boxes names for large blobs read whole, and its inside is Chapter 22's problem.

At senior level, three things are hard. Upload and transcoding: a resumable upload in parts, a graph of tasks that turns one source into several encoded versions, and workers that may run twice. Adaptive bitrate: short segments, the manifests that list them, and a player that does the choosing, with HLS and DASH as examples. And the cost curve: popular videos against the long tail, with the egress arithmetic done in full.

Sketch your own answer before any of that, against a 45-minute timer. When it rings, follow the bytes through your sketch: where do they come from for the millionth viewer, and for the tenth viewer of a video nobody else wants? The lessons keep that clock: Scope runs to minute ten, First Design to twenty, Scaling It to thirty, and the deep dives and curveballs to the end.

The 45 minutes of this problem, lesson by lesson
Scopeminutes 0-10
→
First Designminutes 10-20
→
Scaling Itminutes 20-30
→
Deep Divesminutes 30-45

Lessons in This Chapter