Requirements & scope
Problem Statement & Requirements
Functional Requirements
- Upload videos -- creators upload video files (up to 10 GB), system processes and stores them
- Stream videos -- viewers watch videos with smooth playback, adaptive quality
- Search & discovery -- search by title/tags, homepage recommendations, trending
- Video metadata -- title, description, tags, thumbnails, view count, likes/dislikes
- Comments -- threaded comments on videos
- Subscriptions / channels -- users subscribe to creators, see new uploads in feed
- Watch history & resume -- track progress, resume from where user left off
- Live streaming (brief mention) -- real-time broadcast with minimal delay
Non-Functional Requirements
- Low startup latency -- video begins playing within 2 seconds
- No buffering -- adaptive bitrate prevents rebuffering on bandwidth changes
- High availability -- 99.99% uptime for playback (upload can tolerate brief outages)
- Global reach -- low latency worldwide via CDN
- Scalability -- 1B+ DAU, 500+ hours of video uploaded per minute
- Cost efficiency -- storage and bandwidth are the dominant costs
Out of Scope
- Monetization / ads system (that's a separate design)
- Creator analytics dashboard
- Copyright detection (Content ID) -- mentioned briefly
- Short-form video (TikTok-style) -- similar but different optimization profile
Scale estimations
Scale Estimations
Users & Content
| Metric | Value |
|---|---|
| Daily Active Users (DAU) | 1B |
| Total videos | 1B |
| New video uploads / day | 500 hours/min x 60 x 24 = 720,000 hours/day |
| Videos uploaded / day | ~5M (avg 8.6 min each) |
| Average video length | 8 minutes |
| Average views per user per day | 5 videos |
| Total video views / day | 5B |
Storage
| Metric | Value |
|---|---|
| Raw video avg size (1080p, 8 min) | ~1.5 GB |
| Raw uploads / day | 5M x 1.5 GB = ~7.5 PB/day |
| Transcoded versions per video | 5 resolutions x 3 codecs = ~15 versions |
| Avg transcoded size (all versions) | ~3 GB total per video |
| Transcoded storage / day | 5M x 3 GB = ~15 PB/day |
| Total storage (accumulated) | ~exabytes |
| Thumbnail storage / day | 5M x 5 thumbs x 50 KB = ~1.25 TB |
Bandwidth
| Metric | Value |
|---|---|
| Avg video bitrate (mixed quality) | 5 Mbps |
| Concurrent viewers (peak) | ~200M |
| Peak egress bandwidth | 200M x 5 Mbps = ~1 Petabit/s |
| Daily egress | ~500 PB/day |
Transcoding
| Metric | Value |
|---|---|
| Videos to transcode / day | 5M |
| Transcoding time per video (1080p, 8 min) | ~30 min per resolution |
| Total compute needed | 5M x 15 versions x 30 min = enormous |
| Transcoding cluster size | 10,000+ machines |
Layered architecture
Phase 1 of 4 · Client & edge
Start with the entry points
First, define who uses the system and where requests enter. This is the boundary of the design, not yet a complete request path.
- Creator client
- Upload large files in resumable chunks instead of sending video through an application server.
- Upload service
- Authorize uploads and create a durable video record before starting the processing pipeline.
- Player
- Choose a rendition using buffer health and measured throughput, then adapt during playback.
This first layer defines the system boundary. The next chapters add application logic and data dependencies. After examining the request paths and tradeoffs, we will add operational safeguards and bring the complete architecture together.
API & contracts
Phase 2 of 4 · Application & compute
Add the application logic
Keep the entry points and add the services that do the work. Give each service a clear responsibility before defining its contracts. Storage and background dependencies come next.
- Transcode workers
- Create a ladder of renditions asynchronously; isolate failed transcode jobs for retry.
- Video service
- Expose playable manifests only after required outputs are ready.
Creating an upload should return an upload ID and a resumable transfer contract. Playback needs a different contract: authorization, a manifest, and URLs for the available segments. A client polling processing status must be able to distinguish uploading, processing, ready, and failed instead of guessing readiness from the presence of an object.
Data model
Phase 3 of 4 · Data & async work
Connect data and background work
The services now need their dependencies: durable state, fast lookups, or work that continues outside a request. Separate these responsibilities rather than treating every component as a database.
- Object storage
- Store immutable media segments separately from video metadata.
- CDN
- Serve popular segments near viewers and shield the origin from repeated cache misses.
Data Model
Video Metadata (MySQL / Vitess)
View Counts at Scale
Core design decisions
Do not make viewers wait for the original video to finish every processing task. Define which renditions are sufficient for initial playback and publish a manifest only when its referenced segments are available. Adaptive playback chooses among prepared renditions; it does not ask the origin to re-encode each segment for each viewer.
Request flows
Video Upload Flow
Multipart Upload for Large Files
Transcoding Pipeline -- The Heart of the System
Why Transcode?
Transcoding Output Matrix
Transcoding Architecture
Parallel Transcoding Strategy
Video Playback Flow
Performance & caching
Cost Optimization
Advanced design
Adaptive Bitrate Streaming (ABR)
How ABR Works
HLS Manifest Example
ABR Algorithm (Client-Side)
CDN Architecture
Multi-Tier CDN Strategy
CDN Content Routing
Video Player Architecture
Recommendation Engine (Brief)
Live Streaming (Brief Overview)
Content Moderation & Copyright
Edge cases
A creator may delete a video while cached segments remain at the edge. Decide how authorization expiry and cache invalidation limit continued access. Also handle partial processing failure: a broken high-resolution rendition need not make healthy lower-resolution versions disappear, but the manifest must not advertise missing segments.
Tradeoffs
Tradeoffs & Design Decisions Summary
| Decision | Option A | Option B | Chosen | Why |
|---|---|---|---|---|
| Upload | Through API server | Direct to S3 (presigned URL) | Direct S3 | Avoids bottleneck; API servers don't handle GB-sized files |
| Transcoding | Single machine per video | Parallel segment encoding | Parallel | 1-hour video: 5 min vs 2 hours |
| Streaming protocol | Progressive download | HLS / DASH (ABR) | HLS/DASH | Adaptive quality; works on all devices; industry standard |
| Segment duration | 2 seconds | 6 seconds | 6 seconds | Shorter = more requests + overhead; longer = coarser ABR switching. 6s is the industry sweet spot |
| Codec | H.264 only | H.264 + VP9 + AV1 | All three | H.264 for compatibility; VP9/AV1 for bandwidth savings on modern devices |
| CDN | Third-party (Akamai) | Own CDN (Open Connect) | Depends on scale | YouTube/Netflix: own CDN. Startups: third-party |
| View counts | Sync DB update | Async Kafka -> Redis -> DB | Async | Can't do 58K writes/sec to one row; batch aggregation |
| Storage | Single tier | Hot/warm/cold tiering | Tiered | 80% of views on 5% of videos; cold storage saves 60%+ cost |
| Transcoding scope | All resolutions immediately | Lazy (popular = more codecs) | Lazy | 90% of videos never need 4K; saves 40% compute |
| Thumbnails | Single auto-generated | Multiple + creator choice | Multiple | Auto-generate 3 candidates; let creator pick or A/B test |
| Metadata DB | NoSQL | MySQL (Vitess sharded) | MySQL/Vitess | Relational queries needed (joins for search, channels); Vitess scales MySQL horizontally |
Reliability & fault tolerance
Phase 4 of 4 · Operations & resilience
Add operational safeguards
With the request paths and tradeoffs established, add the controls that help detect trouble and keep the system operating. The final diagram retains every layer introduced so far.
- Playback telemetry
- Optimize user-visible startup delay, buffering, and cost rather than raw throughput alone.
Make transcoding jobs repeatable using stable input versions and deterministic output locations. A worker can crash after writing a segment but before reporting success. Validate existing output on retry, and publish readiness atomically enough that players never receive a manifest pointing to unfinished media.
Production architecture
High-Level Architecture
Detailed Architecture (Read vs Write Paths)
Production Architecture
Further exploration
Compare a recorded lecture with a live sports match. The lecture favors reuse and efficient delivery; the match adds an end-to-end freshness budget. Follow where latency accumulates—in capture, encoding, packaging, delivery, and the player’s buffer—before choosing which safety margin to reduce.
Interview playbook
Interview Tips
Separate upload from playback -- These are completely different systems. "Let me design the write path (upload + transcode) first, then the read path (streaming)." This structures your answer clearly.
Transcoding is the centerpiece -- Spend the most time here. Explain why you need multiple resolutions + codecs, parallel segment encoding, and the output matrix.
ABR is what makes streaming work -- "The player dynamically switches quality based on bandwidth. This is why Netflix doesn't buffer on your phone even on a spotty connection." Draw the segment timeline with quality switches.
CDN is critical for scale -- "1 Petabit/s of egress bandwidth. No origin server handles that. You need a multi-tier CDN with edge PoPs worldwide." Mention Netflix Open Connect if you know it.
View counts are a distributed systems problem -- "5B views/day. You can't UPDATE a SQL row on every view. Buffer in Kafka, aggregate in Redis, flush to DB." This shows you think about practical bottlenecks.
Presigned URLs for upload -- "The video file goes directly from client to S3. Our API servers never touch the bytes." Simple but important.
Cost awareness differentiates senior candidates -- "Storage is the biggest cost. Tiered storage, lazy transcoding, and AV1 codec migration are how YouTube/Netflix keep costs manageable at exabyte scale."
HLS manifest is worth showing -- Write out the master playlist. It's concrete, shows you know the actual protocol, and takes 30 seconds to draw.
Don't forget startup latency -- "Start with lowest quality for the first 2 segments, then ramp up. This gives sub-2-second time-to-first-frame."
Mention live streaming briefly -- "Live is similar but uses RTMP for ingest and LL-HLS for playback with 2-6 second segments. The key difference is real-time transcoding instead of batch."