Explore / Backend system design

Design a Video Platform (YouTube)

Overview

Design a video sharing platform like YouTube. Creators upload videos from a phone or a studio. Viewers search, open a video and watch it on anything from a 4K TV on fibre to an old phone on a train. Each video shows its view count, likes and comments.

Most of the system is not where candidates spend their time. The work is in three places: getting a 10 GB upload in reliably over flaky connections, turning one upload into dozens of files (resolutions, codecs, segments) quickly and affordably, and delivering tens of terabits per second so that playback starts fast and rarely stalls, which is a content delivery problem much more than a server problem. Write your answer in the Write tab and sketch the architecture in the Diagram tab.

Requirements

Functional

  • Upload videos (up to several hours and tens of GB), with title, description and thumbnail.
  • Watch videos on web, mobile and TV, with quality that adapts to the network.
  • Video page shows view count, likes and comments.
  • Search and a home feed (treat recommendations as a black box).
  • Creators see their processing status and basic analytics.

Non-functional

  • Smooth playback: fast start (around 2 seconds), very few rebuffering stalls.
  • Global reach: viewers everywhere get the video from nearby.
  • Uploads never lost once acknowledged; processing finishes within minutes for typical videos.
  • Highly available reads; eventual consistency is fine for view counts, likes and new uploads appearing in search.
  • Cost-efficient storage and bandwidth, the two biggest bills.

Estimates

Assume 20 million uploads per day with an average length of 5 minutes and an average source file of 200 MB (about 5.3 Mbps), each transcoded into 12 renditions (6 resolutions × 2 codecs) whose total size is about the same as the source. Assume 5 billion views per day, an average of 5 minutes watched per view at 2 Mbps. Work out:

  • Upload rate and daily ingest in bytes.
  • Storage added per day for originals plus renditions.
  • Transcoding work in core-minutes if one core encodes one rendition at roughly real time.
  • Average outgoing bandwidth, and what that implies for serving.
  • View-count writes per second.

Hints

  • A 10 GB upload fails at 93% on a train. What should happen next?
  • Does a 2-hour video have to be encoded from start to finish on one machine?
  • How does a player switch from 1080p to 480p in the middle of a video without stopping?
  • Most views go to a small share of videos, and most videos are rarely watched. How does that change where you store and cache them?
  • A viral video gets a million views a minute. What happens to a single counter row?

Follow-ups

  • How would you support live streaming? What changes?
  • How do you detect re-uploads of copyrighted content?
  • A video is watched once a year. Do you keep all 12 renditions?
  • How do you make processing of a famous creator's upload finish first?
  • How would you measure and improve playback quality across the world?

Write your answer step by step and compare it with the reference solution on GrindPrep.