🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
Search courses…
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Design YouTube

System Design ProblemsVideo Streaming Systems🟢 Free Lesson

Advertisement

System Design Problems

Design YouTube

YouTube serves 2B+ monthly active users with 500+ hours of video uploaded every minute. This design covers video upload pipelines, adaptive streaming, CDN delivery, and recommendation systems.

  • Scale — 2B MAU, 500+ hours uploaded/minute, 1B hours watched/day
  • Storage — Exabytes of video content
  • Streaming — Adaptive bitrate with sub-second startup

YouTube's core challenge is the asymmetric nature: massive storage for uploads, massive bandwidth for streaming.

Requirements Clarification

Functional Requirements

  1. Upload videos with metadata
  2. Stream videos with adaptive quality
  3. Search videos by title/tags
  4. Like, comment, subscribe
  5. View personalized recommendations
  6. Live streaming
  7. Short-form content (Shorts)

Non-Functional Requirements

  1. Availability: 99.99% uptime
  2. Latency: Video starts in < 2 seconds
  3. Durability: Videos must never be lost
  4. Consistency: Eventual consistency for counts
  5. Scale: 1B hours of video watched daily

YouTube's key insight: Video transcoding is the bottleneck. A 1-hour 4K video can take 4+ hours to transcode. The system must process millions of videos in parallel.

Back-of-the-Envelope Estimation

Upload Rate

Uploads per minute=500 hours1 minute8.3 videos/second\text{Uploads per minute} = \frac{500 \text{ hours}}{1 \text{ minute}} \approx 8.3 \text{ videos/second}

Here,

  • 500500=Hours uploaded per minute
  • 8.38.3=Videos per second (avg 1 min each)

Storage Estimation

Per video storage:

  • Original: 10GB (1-hour 4K)
  • Transcoded variants: 10GB × 6 resolutions = 60GB
  • With 3 replicas: 60GB × 3 = 180GB per video

Daily storage (86,400 videos/day): 180GB × 86,400 = 15.5 PB/day

Annual storage: 15.5 PB × 365 ≈ 5.7 EB/year

High-Level Architecture

ClientsCDN EdgeAPI Gateway / Load BalancerUpload ServiceChunked UploadTranscodingPipelineVideo StreamHLS/DASHRecommendationML PipelineSearchIndex/QueryMessage Queue (Kafka)Object Storage(GCS/S3)Video Metadata(MySQL Sharded)User Data(MySQL Primary)Search Index(Elasticsearch)ML Features(Redis/BigTable)

Video Upload Pipeline

ClientUploadIngestServiceVirusScanTranscodeQueueObjectStorage(CDN Origin)Video Upload PipelineChunked upload → Resume support → Parallel processing → Multiple resolutions

Transcoding Pipeline

DfAdaptive Bitrate Streaming

Videos are transcoded into multiple resolutions (240p to 8K) and bitrates. The player dynamically switches quality based on network conditions. This ensures smooth playback across varying bandwidth.

Transcoding Cost

Time=Video Duration×ComplexityParallel Workers\text{Time} = \frac{\text{Video Duration} \times \text{Complexity}}{\text{Parallel Workers}}

Here,

  • ComplexityComplexity=Encoding complexity factor (1x-10x)
  • ParallelWorkersParallel Workers=Number of transcoding workers

Transcoding Parallelism

A 1-hour 4K video at 10x complexity = 10 hours of CPU time.

With 100 parallel workers: 10 hours / 100 = 6 minutes

To process 86,400 videos/day (1 per second average): Need 86,400 × 10 / 86400 = 10,000 CPU cores

Adaptive Streaming

ABR Decision

Qualityn=argmaxqQ{q:bitrate(q)bandwidthest}\text{Quality}_n = \arg\max_{q \in Q} \{ q : \text{bitrate}(q) \leq \text{bandwidth}_{\text{est}} \}

Here,

  • QQ=Available quality levels
  • bandwidthextestbandwidth_{ ext{est}}=Estimated available bandwidth

HLS vs DASH

FeatureHLSDASH
ProtocolApple's HTTP Live StreamingDynamic Adaptive Streaming
Segment FormatMPEG-TSfMP4/CMAF
Manifestm3u8MPD
DRMFairPlayWidevine/PlayReady
Latency6-30 seconds2-10 seconds

CDN Architecture

DfMulti-CDN Strategy

YouTube uses a multi-CDN approach with Google's own CDN (GGC) deployed inside ISPs. Popular content is cached at edge nodes close to users. Long-tail content is served from regional data centers.

CDN Cache Hit Ratio

Hit Ratio=Requests served from cacheTotal requests\text{Hit Ratio} = \frac{\text{Requests served from cache}}{\text{Total requests}}

Here,

  • HitRatioHit Ratio=Fraction of requests served from edge
  • TargetTarget=> 95% for popular content

Recommendation System

DfCollaborative Filtering + Deep Learning

YouTube's recommendation system uses a two-stage approach:

  1. Candidate Generation: Retrieve hundreds of candidate videos using collaborative filtering
  2. Ranking: Score candidates using a deep neural network

Recommendation Score

P(watch)=f(user history,video features,context)P(\text{watch}) = f(\text{user history}, \text{video features}, \text{context})

Here,

  • userhistoryuser history=Watch history, likes, search queries
  • videofeaturesvideo features=Title, tags, thumbnail, duration
  • contextcontext=Time of day, device, location

Data Model

Video Schema

Video=(video_id,user_id,title,description,tags[],duration,status,upload_time)\text{Video} = (video\_id, user\_id, title, description, tags[], duration, status, upload\_time)

Here,

  • videoidvideo_id=Unique video identifier
  • statusstatus=processing/ready/failed
  • durationduration=Video duration in seconds

Practice Exercises

  1. Upload Design: Design a resumable upload system that handles 10GB files. How do you handle network failures mid-upload?

  2. Transcoding: How would you prioritize transcoding? Should a viral video be transcoded before an old personal video?

  3. Live Streaming: Design a live streaming system with < 5 second latency. How does this differ from VOD?

  4. Storage Optimization: Propose a storage tiering strategy for videos with decreasing popularity over time.

Key Takeaways:

  • Video upload uses chunked upload with resumable support
  • Transcoding is the bottleneck: requires massive parallelism
  • Adaptive bitrate streaming ensures smooth playback across networks
  • Multi-CDN with edge caching for low-latency delivery
  • Recommendation system uses two-stage ML pipeline

What to Learn Next

-> Design Netflix Content delivery and adaptive streaming.

-> Design Instagram Media delivery and feed generation.

-> Design Amazon E-commerce at scale.

-> Design Google Search Web-scale indexing and ranking.

-> Back Pressure Managing load in streaming systems.

-> Caching Strategies CDN and edge caching patterns.

Premium Content

Design YouTube

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
💼Interview Prep
📜Certificates
🤝Community Access

Already a member? Log in

Need Expert System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement