Skip to content

Case Study: Video Streaming (Netflix/YouTube)

Difficulty: Advanced | Category: Data-Intensive & High Bandwidth | Similar Systems: Twitch, Hulu

Designing a video streaming platform is unique because the challenge isn't just request volume (QPS)—it's raw network bandwidth and massive storage requirements.


1. Requirements Clarification

Functional Requirements

  • Upload: Content creators (or internal studios) can upload raw video files.
  • Streaming: Users can watch videos on different devices (Mobile, TV, Web) at varying bandwidths.
  • Search: Users can search for video titles.

Non-Functional Requirements

  • No Buffering: Video must stream smoothly with minimal latency.
  • High Availability: Must survive regional data center outages.
  • Global Reach: Fast streaming regardless of geographic location.

2. Back-of-the-Envelope Estimation

Assume 200 million users.

  • Storage: If 1,000 hours of video are uploaded daily. A 1-hour raw 4K video is ~20 GB.
    • 1000 * 20 GB = 20 TB/day of raw video.
    • After transcoding into 5 different resolutions/codecs, storage multiplies to ~100 TB/day.
  • Bandwidth: If 50 million users watch concurrently during peak hours 3 Mbps (HD quality):
    • 50M * 3 Mbps = 150 Terabits per second (Tbps) of egress bandwidth.

WARNING

150 Tbps is massive. A standard central data center cannot serve this. The architecture requires a heavily optimized Content Delivery Network (CDN) pushed to the absolute edge of the network.


3. High-Level Architecture: The Two Planes

Streaming architectures are split into two distinct halves: the Control Plane and the Data Plane.

A. The Control Plane (Backend Services)

Handles everything except streaming the actual video file. Hosted in a central cloud (like AWS).

  • User Login & Profiles
  • Recommendations & Search
  • Metadata Database (Titles, actors, descriptions)
  • Video Transcoding Pipeline

B. The Data Plane (Video Streaming)

Handles the heavy lifting of delivering video bytes. Hosted on Edge CDNs (e.g., Netflix's Open Connect Network).


4. Deep Dive: Video Transcoding (DAG Pipeline)

When a raw .mp4 is uploaded, it cannot be streamed directly. It must be processed into smaller chunks and different formats.

  1. Chunking: The video is split into small chunks (e.g., 5-second segments).
  2. Transcoding Pipeline: A Directed Acyclic Graph (DAG) of workers processes the chunks.
    • Converts to 1080p, 720p, 480p, 360p.
    • Applies different codecs (H.264 for older devices, AV1 for modern web).
    • Extracts audio tracks and subtitles.
  3. Packaging: The chunks are wrapped in protocols like HLS (HTTP Live Streaming) or DASH (Dynamic Adaptive Streaming over HTTP).

Why chunking? If a user's Wi-Fi drops in speed, HLS allows the player to seamlessly download the next 5-second chunk at 480p instead of 1080p, preventing buffering (Adaptive Bitrate Streaming).


5. Deep Dive: The Edge CDN Strategy

To serve 150 Tbps globally, you cannot stream from AWS us-east-1 to users in India.

  1. ISPs (Internet Service Providers): Companies like Netflix install specialized hardware appliances (Open Connect Appliances) directly inside ISP data centers (Comcast, AT&T, Jio).
  2. Proximity: When you hit "Play", the Control Plane determines your location and ISP and gives your app the IP address of the CDN appliance closest to your house.
  3. Predictive Caching: CDNs have limited storage. Netflix pushes the most popular shows to edge CDNs overnight during off-peak hours based on regional popularity (e.g., caching popular anime heavily in Tokyo edge nodes).

6. Database Selection

  • Video Metadata (Titles, Descriptions): Relational DB (PostgreSQL/MySQL) for ACID compliance and complex queries, cached heavily with Redis.
  • Raw & Processed Video Files: Blob/Object Storage (AWS S3) due to cost-effectiveness and durability for massive unstructured files.
  • Search: Elasticsearch, syncing data from the Metadata DB to provide fast autocomplete and fuzzy searching.

Released under the ISC License.