Design CanvasOpen the canvas

Design a Video Streaming Service

People watch videos on every kind of device, and a small number of creators upload new ones. Watching means fetching many short pieces of the video, which a CDN should serve. Every upload has to be converted into several qualities before it can play, which is slow and heavy, and a new episode of a popular show sends viewers all at once.

Constraints

  • Each video piece must start arriving within 250 ms
  • About 10,000 piece requests per second at peak, and three times that at a premiere
  • Pieces are served from a CDN, and storage should see only the misses
  • Uploads are converted to several qualities in the background, and a burst of uploads must not slow viewers
  • Recommendations help viewers but are optional
  • Keep infrastructure under $14,000 a month

Scenarios to survive

Typical peak

Steady viewing with the usual trickle of uploads.

Interviewer asks: Watching and uploading are very different loads. How do you keep a heavy upload from touching viewers?

A premiere (3x)

A popular show drops and viewing triples.

Interviewer asks: Nearly all viewers want the same handful of video pieces at once. What serves them before storage is touched?

An upload burst

Uploads and conversions jump tenfold for a while.

Interviewer asks: Creators upload a mountain of video. Where does the conversion work wait, and how do viewers stay unaffected?

Recommendations hang

Whatever runs recommendations becomes 20x slower.

Interviewer asks: Recommendations hang. Should playing a video wait for them?

What a good design must do

  • Video pieces start within the latency target at peak
  • The premiere passes
  • Total monthly cost stays within $14,000
  • Pieces are served through a CDN in front of storage
  • Something converts uploads, away from viewers
  • An upload burst does not disturb viewers
  • A hung recommender cannot slow playback
  • The design explains how a video is split into pieces and qualities