Skip to main content
HS
HiSETSuccess
LeetCode Prep

System Design

Comprehensive interview guide: scalability, databases, distributed systems, cloud architecture, and full case-study walkthroughs — plus adaptive quizzes.

Case study

Design YouTube-style Video Streaming

Upload, transcode, and stream video globally with adaptive bitrate and CDN edge delivery.

CDNtranscodingHLS

Requirements

  • Functional: upload video; transcode to multiple resolutions; stream via web/mobile/TV
  • Adaptive bitrate (ABR): HLS/DASH segments; player switches quality by bandwidth
  • Search, recommendations, view counts (eventual consistency OK)
  • Non-functional: playback start < 2 sec; 99.9% availability for CDN path
  • Scale: 100M DAU; 500K uploads/day; avg 5 min video, 500 MB raw

Back-of-envelope Estimation

MetricCalculationResult
Upload/day500K × 500 MB250 PB/day raw (before dedup/CDN cache)
Upload QPS500K / 86,400~6/sec avg
Views/day100M × 3 videos × 5 min1.5B view-minutes/day
CDN egress peakAssume 20M concurrent × 2 Mbps~40 Tbps peak (CDN scale)
Transcode fleet500K × 10 min video × 4 renditionsGPU worker pool; queue-based

API Design

EndpointDescription
POST /v1/videos/upload/initReturns uploadId + pre-signed multipart URLs
POST /v1/videos/{id}/completeTriggers transcode pipeline
GET /v1/videos/{id}/manifest.m3u8HLS master playlist (CDN cached)
GET /v1/videos/{id}Metadata, thumbnails, view count
POST /v1/videos/{id}/viewAsync view increment (batched)

Data Model

EntityStorage
videosvideo_id, user_id, title, status, duration, created_at — SQL
renditionsvideo_id, resolution, bitrate, manifest_path — SQL
segmentsBlob paths in S3/CDN: /{video_id}/{rendition}/seg_{n}.ts
view_countsvideo_id, count — Redis + periodic flush to SQL

High-level Design

Upload & playback pipeline
Upload ──► S3 (raw) ──► Transcode Queue ──► GPU Workers
                                              │
                                    S3 segments (360p/720p/1080p)
                                              │
                                    CDN origin ──► Edge POPs worldwide
                                              │
                                    Client HLS player (ABR)

Deep Dive: Transcoding Pipeline

  1. Probe raw file: duration, codec, resolution
  2. Generate renditions: 360p@800kbps, 720p@2.5Mbps, 1080p@5Mbps
  3. Segment into 2–6 sec .ts chunks; generate .m3u8 playlists
  4. Thumbnail sprites every 10 sec for seek preview
  5. Mark video status = ready; purge CDN manifest cache

Deep Dive: CDN & ABR

Player downloads master playlist, picks initial rendition by bandwidth estimate, switches on buffer health. Popular videos cached entirely at edge; long tail fetched from regional origin shield. Signed URLs prevent hotlinking.

First segment optimization

Encode first segment at lower quality for faster time-to-first-frame; upgrade within 2 seconds.

Failure Modes & Monitoring

SLOTarget
Time to first frame p99< 2 sec
Transcode completion p99< 2× realtime
CDN availability99.99%
  • Alert: transcode queue > 1 hr backlog, CDN origin 5xx, rebuffer rate > 5%
  • Dashboard: egress by region, popular video cache hit ratio, upload failure rate