Designbench

Lesson 6.8 · 25 min

Video streaming

Watch fixed 1080p freeze in a train tunnel while adaptive players keep going, find the cheapest number of videos to keep on the CDN, and cut a 300-minute encode to 3 by chunking.

The idea in plain words

A video site takes one uploaded file, turns it into many versions for different screens and speeds, and sends small pieces to millions of viewers. The player keeps switching quality so the video doesn’t stop to buffer.

The problem it solves

One uploaded video must play smoothly on a slow phone and a 4K TV, for millions of viewers, without huge delivery bills.

How it works

  1. The upload goes straight to object storage.
  2. It is split into chunks and transcoded in parallel into a ladder of qualities (240p up to 4K).
  3. Each quality is cut into short segments of a few seconds.
  4. The player downloads segments one at a time and picks the quality of the next one based on current speed (adaptive bitrate).
  5. Popular videos are served from CDN servers near viewers.

Example

On a train, your speed drops from 10 Mbit/s to 2 Mbit/s. The player notices and fetches the next 4-second segment in 480p instead of 1080p. The picture gets softer for a moment, but the video never stops to buffer.

Key terms

Transcoding
Converting a video into other formats, sizes and bitrates.
Bitrate ladder
The set of qualities made for each video, such as 240p to 4K.
Segment
A few seconds of video; players download one at a time.
Adaptive bitrate (ABR)
The player picks the quality of each next segment based on your current speed.
Egress
Data sent out to viewers; usually the biggest cost.

In this lesson you'll learn

Sections

  1. Requirements and numbers
  2. API and data
  3. Architecture
  4. Deep dive: adaptive bitrate
  5. Deep dive: cost and speed
  6. Design review

Cheat sheet

1 Mbps × 1 hour450 MB
Uploadresumable, straight to storage
Transcodechunk × rendition DAG on a queue
PlaybackHLS/DASH segments + ABR
DeliveryCDN head, cheaper long tail

The interactive simulations and the scored design review load with JavaScript.