Design a Video Streaming Service (YouTube/Netflix)

Build a global video platform with encoding pipelines, CDN distribution, adaptive streaming, and recommendation systems for billions of hours of content.

System Requirements

Functional Requirements

  • Upload videos (multiple formats, up to 4K resolution)
  • Transcode to multiple bitrates and formats
  • Global video streaming with adaptive bitrate
  • Video search and discovery
  • User profiles and video management
  • Comments, likes, and social features
  • Live streaming capabilities
  • Content recommendations based on viewing history

Non-Functional Requirements

  • 2B hours watched per day (YouTube scale)
  • 500 hours of video uploaded per minute
  • Support 4K, 1080p, 720p, 480p, 360p streaming
  • Video start time < 2 seconds globally
  • Rebuffering ratio < 0.5%
  • 99.9% availability for streaming
  • Support 50M+ concurrent viewers
  • Global CDN with <200ms latency

Capacity Estimation

Video Platform Scale

Read vs Write
1x ratioUpload
1000x ratioWatch
Content Type
5% splitLive
95% splitVOD
Quality Distribution
30% viewsSD
70% viewsHD+

Traffic Analysis

Daily Watch Hours
YouTube-scale consumption
2B hours
Upload Rate
26,000 hours uploaded daily
500 hrs/min
Peak Concurrent
Global prime time overlap
50M users
Bandwidth Peak
Global aggregate throughput
40 Tbps

Storage Requirements

Raw Video Storage
100+ petabytes total content
Transcoded Versions
5x storage multiplication factor
Daily Growth
1 petabyte new content/day

Video Encoding Pipeline

Upload Path:
Client → Upload Service → Object Storage (Raw Video)
Transcoding Queue → Worker Nodes (FFmpeg/GPU)
Multiple Bitrates/Formats → CDN Origin Servers
Metadata Extraction → Search Index + Recommendations
Streaming Path:
Client Request → CDN Edge → Adaptive Bitrate Selection
Video Segments (HLS/DASH) → Progressive Download
Player Buffer Management → Quality Adaptation

Video Format Matrix

ResolutionBitrateUse CaseStorage FactorComplexity
4K (2160p)35-45 MbpsPremium content, high-end devices1x (reference)Very High
1080p HD8-12 MbpsStandard HD viewing0.3xHigh
720p4-6 MbpsMobile devices, medium bandwidth0.15xMedium
480p2-3 MbpsLow bandwidth connections0.08xLow
360p1-1.5 MbpsVery low bandwidth, mobile0.05xLow

System Architecture

Upload Service

Multipart upload, S3/GCS, chunked transfer
Purpose:
Handle video file uploads with resumable uploads
Scale:
500 hours uploaded/minute

Transcoding Pipeline

FFmpeg, Kubernetes jobs, GPU acceleration
Purpose:
Convert videos to multiple formats and bitrates
Scale:
1M+ hours processed/day

CDN Network

CloudFront/Cloudflare, adaptive bitrate
Purpose:
Global video delivery with edge caching
Scale:
200+ edge locations worldwide

Metadata Service

Elasticsearch, ML recommendation engine
Purpose:
Video metadata, search indexing, recommendations
Scale:
100B+ video views/day

Upload Tier

• Resumable multipart uploads
• Virus scanning & validation
• Duplicate detection
• Content moderation queue

Processing Tier

• Horizontal transcoding cluster
• Priority queue management
• GPU-accelerated encoding
• Quality assurance checks

Delivery Tier

• Global CDN distribution
• Edge caching optimization
• Adaptive bitrate streaming
• Analytics & monitoring

Streaming Optimizations

1

Adaptive Bitrate Streaming (ABR)

Dynamically adjust video quality based on network conditions

Benefit:
60% reduction in rebuffering events
Implementation:
HLS/DASH protocols, client-side bandwidth estimation
2

Predictive Caching

Pre-cache popular content at edge locations

Benefit:
80% cache hit rate for trending videos
Implementation:
ML-based popularity prediction, proactive cache warming
3

Smart Thumbnails

Generate multiple thumbnail options and A/B test

Benefit:
20% increase in click-through rates
Implementation:
Computer vision for scene detection, user engagement analysis
4

Progressive Download

Start playback while continuing to download

Benefit:
Sub-2 second video start time
Implementation:
Segment-based streaming, buffer optimization

Performance Metrics

Video Quality Metrics

Video Start Time
Time to first frame globally
< 2 seconds
Rebuffering Ratio
Industry-leading performance
< 0.5%
Quality Adaptation
Network change response time
< 500ms
CDN Cache Hit Rate
Popular content cached at edge
85%

Encoding Performance

Encoding Speed
For 1080p content with GPUs
10x real-time
Processing Queue
Average wait time for uploads
< 30 minutes
Storage Efficiency
Advanced codecs vs H.264
60% savings
Parallel Jobs
Peak transcoding capacity
10K concurrent

Technical Challenges & Solutions

1

Processing Speed vs Quality

Problem: Balance between encoding speed and video quality at scale
Solution: Multi-pass encoding with quality-based rate control
Implementation: Hardware acceleration (GPU/ASIC), parallel processing
2

Format Compatibility

Problem: Support diverse devices and browsers with different codecs
Solution: Multiple codec support: H.264, H.265, VP9, AV1
Implementation: Progressive codec adoption, fallback mechanisms
3

Storage Optimization

Problem: Massive storage requirements for multiple quality versions
Solution: Intelligent tiering, compression optimization, cold storage
Implementation: S3 Intelligent Tiering, automated lifecycle policies
4

Real-time Processing

Problem: Live streaming requires real-time low-latency transcoding
Solution: Dedicated live transcoding pipeline with chunked processing
Implementation: WebRTC ingestion, low-latency HLS/DASH streaming

Database Design

Video Metadata

videos table: - video_id (UUID, PK) - user_id (UUID, indexed) - title (varchar, full-text indexed) - description (text) - tags (JSON array) - duration (seconds) - upload_date (timestamp) - view_count (bigint, default 0) - like_count (int, default 0) - status (processing/ready/error) - thumbnail_url (varchar) - privacy_setting (public/private/unlisted)

Video Files

video_files table: - file_id (UUID, PK) - video_id (UUID, FK) - resolution (varchar) - bitrate (int) - format (varchar) - codec (varchar) - file_size (bigint) - storage_path (varchar) - created_at (timestamp) Index: (video_id, resolution) for ABR

Analytics Schema

video_analytics table (time-series): - event_id (UUID, PK) - video_id (UUID, indexed) - user_id (UUID, nullable) - event_type (view/like/share/comment) - timestamp (timestamp) - session_id (UUID) - device_type (mobile/desktop/tv) - geo_location (varchar) - watch_duration (int, for view events) Partitioned by date for efficient queries

Practice Questions

1

Design a fault-tolerant transcoding pipeline. How do you handle failed jobs and ensure all videos are processed?

2

How would you implement adaptive bitrate streaming? Design the client-side logic for quality switching.

3

Design a recommendation system for video content. What signals would you use and how would you scale it?

4

How would you handle live streaming? What are the differences in architecture compared to video-on-demand?

5

Design a content moderation system. How do you automatically detect and flag inappropriate content at scale?