Full answer
Requirements
Functional:
- Creators upload videos (up to several GB); viewers watch them on web, mobile and TV.
- Playback adapts to network speed; seeking is quick.
- Video metadata (title, description, thumbnails), view counts, likes. Search and recommendations exist but are out of scope here.
Non-functional:
- Playback starts fast (target under about 2 seconds) and rarely rebuffers.
- Uploaded videos are never lost; processing can take minutes.
- Global reach and very high read volume; cost of storage and bandwidth matters a lot.
Capacity estimates
Assumptions: 1M uploads per day; average length 5 minutes; average raw upload 300 MB; all renditions together about 150 MB per video; 1B views per day; average 5 minutes watched at an average 3 Mbps; transcoding the full ladder costs 2 CPU-minutes per minute of video; peak factor 2.
- Upload ingest: 1M x 300 MB = 300 TB per day of originals (kept in a cold tier).
- Transcoded output: 1M x 150 MB = 150 TB per day; with 3 copies, 450 TB per day; about 164 PB per year.
- Egress per view: 300 s x 3 Mbps = 900 megabits = 112.5 MB. Per day: 1B x 112.5 MB = 112.5 PB. Average bandwidth: 112.5 PB x 8 / 86,400 s = about 10.4 Tbps; about 21 Tbps at peak.
- Transcoding compute: 1M x 5 min x 2 = 10M CPU-minutes per day = about 167,000 CPU-hours per day, about 6,900 cores busy around the clock.
- Watch page metadata reads: about 1B per day = about 11,600 per second; easily cached.
API
POST /v1/uploads {"filename": "...", "size": 3221225472} -> {"upload_id", "upload_url"}
PUT <upload_url> (resumable chunks, Content-Range)
POST /v1/videos {"upload_id", "title", "description"} -> {"video_id", "status": "processing"}
GET /v1/videos/{id} metadata, status, manifest URL
GET https://cdn.example.com/v/{id}/master.m3u8 HLS master playlist (renditions)
GET https://cdn.example.com/v/{id}/720p/seg_00042.ts
Data model
videos:video_id,owner_id,title,status(uploading, processing, ready, failed),duration,created_at.renditions:video_id,resolution,bitrate,codec,manifest_path.processing_jobs:video_id,step,segment_index,state,attempts.- Counters for views and likes in a separate counter service.
- Bytes (originals, segments, thumbnails) in object storage; only paths in the database.
High-level design
flowchart LR
CR[Creator] --> UP[Upload service] --> RAW[(Object storage: originals)]
UP --> Q[Job queue]
Q --> SPLIT[Splitter]
SPLIT --> TX[Transcode workers x N]
TX --> PKG[Packager: HLS / DASH + thumbnails]
PKG --> OUT[(Object storage: segments)]
PKG --> META[(Video metadata DB)]
OUT --> CDN[Global CDN]
V[Viewer] --> API[Watch API] --> META
V --> CDNProcessing pipeline
- Upload is resumable: the client sends chunks with offsets, so a dropped connection resumes rather than restarts.
- A job validates the file, then splits it into short pieces (for example 10 seconds at keyframes).
- Transcode workers convert pieces in parallel to a bitrate ladder (for example 240p to 1080p, and 4K where uploaded) in one or more codecs. Parallel segments turn a 1-hour video into many small jobs.
- The packager produces HLS and DASH manifests and segments, generates thumbnails, and marks the video ready.
- Each step is idempotent and retried from the job table; a failed piece is retried alone.
Playback
The player downloads the master manifest, picks a starting rendition, and requests segments from the CDN. It measures download speed and buffer level and switches rendition between segments (adaptive bitrate). Popular videos stay hot in edge caches; long-tail videos are fetched from origin on demand, with an origin shield layer to protect object storage.
Bottlenecks and trade-offs
- Bandwidth cost dominates. Better codecs (AV1, VP9, HEVC) reduce bytes per view at the cost of much more transcoding CPU; apply them first to popular videos, where savings are largest.
- Storage: keep every rendition for popular videos, fewer renditions or on-demand transcoding for videos that are rarely watched; move originals to archive storage.
- Transcoding spikes are absorbed by the queue and autoscaled or spot workers; a creator waits longer, but nothing breaks.
- View counts are aggregated asynchronously from playback events, with fraud filtering; exact real-time counts are not required.
- Segment length: shorter segments switch quality faster and start sooner but add request overhead and slightly worse compression.
By level
Fresher: Explain upload to storage, converting video into several qualities, and serving it from a CDN so the player can switch quality. A fresher should know why video is served from a CDN.
Mid: Estimate storage, egress and transcoding compute, design the job pipeline and data model, and explain manifests and segments. Expect careful egress math with bits and bytes kept apart.
Senior: Address cost optimisation with codecs and storage tiers, origin shielding, multi-CDN, live streaming differences, failure recovery in the pipeline and global capacity planning. The senior answer treats bandwidth and storage cost as first-class design inputs.
Key points
- Resumable uploads into object storage, then an asynchronous, parallel transcoding pipeline
- Bitrate ladder packaged as HLS or DASH segments for adaptive playback
- Egress of about 112.5 PB per day (about 10.4 Tbps) requires a CDN
- Metadata in a database, bytes in object storage
- Codec and storage tiering choices trade CPU against bandwidth and storage cost
Common mistakes
- Streaming video bytes from application servers
- Transcoding whole long videos on one machine
- Confusing megabits and megabytes in bandwidth math
- Keeping every rendition of every video in the hot tier forever
Follow-ups
- How would you support live streaming instead of uploads?
- How do you decide which videos get the expensive codec?
- How would you prevent a single viral video from overloading the origin?
Tips
- Do the egress arithmetic carefully with bits and bytes
- Split the design into upload, processing and playback paths
- Explain adaptive bitrate in one clear sentence
Evaluation rubric
- Requirements separate upload, processing and playback
- Correct storage, egress and compute math
- Pipeline design with parallel, idempotent steps
- CDN, adaptive bitrate and cost trade-offs discussed