Labs

System lab · medium · 32 min

YouTube: Video platform

Upload, transcode into many renditions, and stream at the right quality.

A video platform looks like "upload a file, play a file". It isn't. The file someone uploads from their phone is the wrong format, the wrong size and the wrong shape for almost everyone who will watch it. And the watching side moves more bytes than nearly any other kind of system on the internet.

In this lab you'll design a platform modelled on YouTube from a blank page. Most of the interesting decisions turn out to be about bytes, not requests.

The brief

Creators upload videos. Viewers watch them on phones, laptops and TVs, on everything from fibre to a patchy 3G connection in a moving train. A viewer should press play and see video within a second or two, and it should keep playing without stalling even when their network gets worse.

In scope:

  • Uploading a video, including large files over bad connections.
  • Processing it into formats every device can play.
  • Streaming it to viewers with adaptive quality.
  • A video page with title, description and a view count.

Out of scope: recommendations and the home feed, comments, live streaming, search, ads, copyright matching and creator analytics. Each is a big system of its own.

Requirements

Functional

  • A creator can upload a video file of up to 256 GB or 12 hours.
  • Uploads can resume after a dropped connection without starting over.
  • The platform converts each upload into several resolutions and formats.
  • A viewer can play any published video on any common device.
  • Playback quality adapts to the viewer's bandwidth as it changes.
  • Each video shows a view count.

Non-functional

  • Start fast: video begins playing in under 2 seconds for most viewers.
  • Few stalls: rebuffering under 1% of watch time.
  • Uploads are never lost once the platform says "upload complete".
  • Processing is reasonably quick: a 10-minute video is watchable within a few minutes, at least in a low resolution.
  • Global: viewers in every country get similar start times.
  • View counts can lag by minutes. Nobody needs them exact.
  • View counts reflect real viewers. Bought or scripted views must not count, because counts drive ranking and creators' pay.