System Design Problems
Design a Video Streaming Platform
A video streaming platform enables users to upload, transcode, and watch videos with adaptive bitrate streaming. YouTube serves over 1 billion hours of video daily, requiring sophisticated transcoding pipelines and CDN infrastructure.
- Upload Pipeline â Accept large video files and process them asynchronously
- Transcoding â Convert videos to multiple resolutions and formats
- Adaptive Streaming â Serve the best quality based on network conditions
Video is the most bandwidth-intensive content on the internet. A single 4K video can be 100 GB before transcoding. The system must handle upload, processing, storage, and delivery efficiently.
Requirements
Functional Requirements
- Users can upload videos (up to 4 hours, 4K resolution)
- Transcode videos into multiple resolutions (240p to 4K)
- Adaptive bitrate streaming (HLS/DASH)
- Video playback with buffering and seeking
- Video metadata (title, description, tags)
- Like, comment, and subscribe features
- Content moderation and copyright detection
Non-Functional Requirements
- Upload: Support 500 hours of video uploaded per minute
- Playback: Start playing within 2 seconds
- Availability: 99.99% for video playback
- Latency: First frame < 2 seconds
- Scale: 1 billion hours of video watched daily
Back-of-the-Envelope Estimation
High-Level Architecture
Detailed Design
Video Upload Pipeline
- Client requests upload URL from API
- API returns pre-signed S3 URL for each chunk
- Client uploads chunks in parallel to S3
- Upload service tracks chunk completion
- On completion, trigger transcoding pipeline
Transcoding Pipeline
Adaptive Bitrate Streaming (HLS)
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360
stream_360p.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2000000,RESOLUTION=1280x720
stream_720p.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080
stream_1080p.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=15000000,RESOLUTION=3840x2160
stream_4k.m3u8
Video Metadata
CREATE TABLE videos (
id UUID PRIMARY KEY,
user_id BIGINT NOT NULL,
title VARCHAR(500),
description TEXT,
duration INT, -- seconds
status VARCHAR(20), -- processing, ready, failed
created_at TIMESTAMP,
view_count BIGINT DEFAULT 0
);
CREATE TABLE video_variants (
video_id UUID REFERENCES videos(id),
resolution VARCHAR(10), -- "1080p"
bitrate INT, -- bps
codec VARCHAR(10), -- "h264", "h265"
file_path TEXT,
file_size BIGINT,
PRIMARY KEY (video_id, resolution)
);
Practice Exercises
-
Design: How would you implement a video seeking feature that allows jumping to any point in a 4-hour video within 500ms? What caching and indexing strategies are needed?
-
Scale: If YouTube uploads 500 hours of video per minute, estimate the transcoding cluster size needed assuming each machine can transcode 1 hour of video in 2 hours.
-
Optimization: How would you implement a video deduplication system that detects re-uploads of the same video with different encodings? What fingerprinting algorithm would you use?
-
Cost: Design a tiered storage system that moves old videos from hot (SSD) to warm (HDD) to cold (Glacier) storage based on access patterns.
What to Learn Next
-> CDNs Edge caching and global video delivery.
-> Design Object Storage Storing large video files with high durability.
-> Message Queues Async transcoding pipeline with Kafka.
-> Load Balancing Distributing transcoding work across machines.
-> Caching Strategies Caching popular video segments at CDN edges.
-> Design Realtime Analytics Real-time video viewing analytics and metrics.