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
Traffic Analysis
Storage Requirements
Video Encoding Pipeline
Video Format Matrix
Resolution | Bitrate | Use Case | Storage Factor | Complexity |
---|---|---|---|---|
4K (2160p) | 35-45 Mbps | Premium content, high-end devices | 1x (reference) | Very High |
1080p HD | 8-12 Mbps | Standard HD viewing | 0.3x | High |
720p | 4-6 Mbps | Mobile devices, medium bandwidth | 0.15x | Medium |
480p | 2-3 Mbps | Low bandwidth connections | 0.08x | Low |
360p | 1-1.5 Mbps | Very low bandwidth, mobile | 0.05x | Low |
System Architecture
Upload Service
Multipart upload, S3/GCS, chunked transferTranscoding Pipeline
FFmpeg, Kubernetes jobs, GPU accelerationCDN Network
CloudFront/Cloudflare, adaptive bitrateMetadata Service
Elasticsearch, ML recommendation engineUpload Tier
Processing Tier
Delivery Tier
Streaming Optimizations
Adaptive Bitrate Streaming (ABR)
Dynamically adjust video quality based on network conditions
Predictive Caching
Pre-cache popular content at edge locations
Smart Thumbnails
Generate multiple thumbnail options and A/B test
Progressive Download
Start playback while continuing to download
Performance Metrics
Video Quality Metrics
Encoding Performance
Technical Challenges & Solutions
Processing Speed vs Quality
Format Compatibility
Storage Optimization
Real-time Processing
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
Design a fault-tolerant transcoding pipeline. How do you handle failed jobs and ensure all videos are processed?
How would you implement adaptive bitrate streaming? Design the client-side logic for quality switching.
Design a recommendation system for video content. What signals would you use and how would you scale it?
How would you handle live streaming? What are the differences in architecture compared to video-on-demand?
Design a content moderation system. How do you automatically detect and flag inappropriate content at scale?