YouTube

Video Streaming

Design a video platform where creators upload large files that are processed into many formats, and viewers everywhere start watching in about a second and keep watching without stalls.

Overview

A video platform has two very different halves. On the write side, a creator uploads one large file, sometimes many gigabytes, and the platform turns it into many smaller versions: several resolutions, in more than one codec, cut into short segments. On the read side, viewers ask for those segments millions of times a second, from phones on slow mobile networks and from 4K TVs on fiber, and expect playback to start at once and never stall.

The write side is mostly a compute problem: encoding video is expensive, so it has to run in parallel and in the right order (a watchable version first). The read side is mostly a bandwidth problem: at our assumptions the platform sends around 200 terabits a second at peak, which only works if nearly all of it comes from caches near viewers rather than from the origin.

Questions to ask first

  • How much is uploaded? — 500 hours of video a minute, about 20 million videos a day
  • How much is watched? — 1 billion hours a day, twice the average at peak
  • Largest upload? — 256 GB or 12 hours, whichever is less (YouTube's documented limit)
  • How soon must a video be watchable? — A low resolution within minutes; higher ones may take hours
  • Which devices? — Phones, browsers and TVs, on networks from slow mobile to fiber
  • Live streaming, ads, copyright? — Out of scope

What you will be able to do

  • Design a resumable upload that survives dropped connections on multi-gigabyte files.
  • Build a processing pipeline that makes a low-resolution version watchable first.
  • Explain adaptive bitrate streaming: renditions, segments, manifests and the player's choice.
  • Estimate delivery bandwidth and explain why caches near viewers, not the origin, carry it.
  • Shard video metadata and count views without a write per view.

Key concepts

  • Resumable upload
  • Transcoding pipeline
  • Encoding ladder
  • Adaptive bitrate streaming
  • Segments and manifests
  • CDN and ISP caches
  • Long tail
  • Sharded metadata
  • Two-stage recommendations

Functional requirements

  • Upload a video file, resuming after a dropped connection
  • Process it into several resolutions and codecs
  • Play it with quality that adapts to the viewer's network
  • Show title, channel, view count and thumbnails on a watch page
  • Show a personalized home page of recommended videos
  • Search videos by title and description

Non-functional requirements

  • Playback starts in under 2 seconds at p90 (a target we chose)
  • Rebuffering under 1% of watch time (a target we chose)
  • A low-resolution version is watchable within minutes of upload; higher ones may take hours
  • No acknowledged upload is ever lost
  • Old, rarely watched videos still play, from slower storage if needed

Interview questions

  • How do you make a new upload watchable quickly?
  • How does adaptive bitrate streaming work?
  • How much bandwidth, and how do you serve it?
  • How do you handle the long tail of rarely watched videos?
  • How do you upload a 50 GB file reliably?
  • How do you count billions of views a day?
  • How would you build the home page recommendations?
  • What happens when an encoding worker crashes halfway?

Sign up free to read the full topic

More System Design topics

Start free on Cariara · Coding problems · System design studio