Design a video streaming service like YouTube

Video is heavy. We design upload, transcoding into many qualities, and streaming that adapts to each viewer's network.

A video file split into streams of different quality

Goal: users upload videos; others watch them smoothly on any device and network.

Requirements

  • Upload large videos reliably.
  • Playback starts quickly and does not stall, on slow and fast connections.
  • Search and metadata (title, views, comments).
  • Huge read:write ratio: many views per upload.

Estimates

Suppose 500,000 uploads a day at an average of 200 MB raw. That is 100 TB a day of raw uploads before transcoding, and several versions of each video multiply it. Viewing bandwidth dominates everything, so the design is a storage and CDN problem.

Upload

  1. Client requests an upload URL; the server returns a presigned URL to object storage.
  2. The client uploads in chunks (multipart/resumable), so a failure doesn't restart everything.
  3. When complete, an event goes to a queue to start processing.

Transcoding

A raw upload can't be sent to every device. A pipeline of workers:

  • Splits the video into short segments (a few seconds).
  • Transcodes each segment into multiple resolutions and bitrates (for example 240p to 1080p or more) and codecs.
  • Creates thumbnails and checks for policy violations.
  • Writes outputs to object storage and updates metadata.

Segments are processed in parallel across many machines, which makes this scale. It is CPU/GPU heavy, so it uses a queue and autoscaling workers.

Streaming: adaptive bitrate

Protocols like HLS and MPEG-DASH publish a manifest listing available qualities and segment URLs. The player downloads segment by segment and switches quality based on measured bandwidth, so playback adapts instead of buffering.

Delivery

Segments are static files, ideal for a CDN. Popular videos are cached at edges close to viewers; rare ones come from origin storage. Most of the cost and engineering effort is here.

Metadata and counters

Titles, owners and comments live in a database; search in a search index. View counts are write-heavy, so buffer them (a queue or Redis) and aggregate, rather than updating a row on each view.

Other concerns

Copyright and moderation checks, access control for private videos (signed URLs), and storage tiering (move cold videos to cheaper storage).

Takeaway: chunked upload, parallel segment transcoding into many qualities, adaptive streaming, and CDN-first delivery.


System Design series, Part 3 (case studies): 5 of 16. Previous: Design a news feed like Instagram or Facebook.

Keep reading