system-design · intermediate
Design YouTube — Upload, Process, and Stream Video
Start here
Design YouTube (simplified):
- Creators upload videos
- System processes multiple resolutions
- Viewers stream playback worldwide with low startup time
- Metadata: title, thumbnails, views (approx OK)
What you will learn
- Scope MVP vs recommendations/live.
- Design resumable upload to object storage.
- Build transcoding pipeline with workers/queues.
- Serve adaptive bitrate via CDN.
- Handle popularity hotspots and thumbnails.
- Discuss consistency of view counts.
Words you need before we begin
| Term | Plain English |
|---|---|
| Transcoding | Convert video into multiple codecs/resolutions. |
| Adaptive bitrate (ABR) | Player switches quality based on bandwidth. |
| HLS/DASH | Playlist-based streaming formats. |
| Origin | Source storage/packager behind CDN. |
| Processing pipeline | Async jobs from upload to playable outputs. |
| Thumbnail | Preview images generated from frames. |
Requirements
MVP
- Upload video
- Process 360p/720p/1080p
- Playback
- Basic channel/video metadata
- View count approximate
Non-functional
- Upload reliability for multi-GB files
- Global playback latency
- Cost awareness (egress + encode)
High-level design
flowchart LR
Creator --> API
Creator --> Upload[Presigned upload]
Upload --> Raw[(Raw object store)]
API --> Q[Transcode queue]
Q --> W[Workers]
W --> Out[(Processed renditions)]
Viewer --> CDN --> Out
API --> Meta[(Metadata DB)]
Step-by-step design
Step 1 — Upload
Resumable chunked upload to raw bucket; complete event triggers processing.
Step 2 — Transcode workers
Workers pull jobs; ffmpeg-like processing; write renditions + HLS playlists; update status PROCESSING → READY.
Step 3 — Metadata
Video id, owner, title, duration, status, playback URLs, thumbnail URLs.
Step 4 — Playback
Player fetches master playlist via CDN; segments cached at edge.
Step 5 — Popularity
Hot videos naturally CDN-cached. Protect origin with cache TTLs and rate limits on miss storms.
Step 6 — Thumbnails & previews
Async generation; store as images on CDN.
Step 7 — View counts
Async events to stream/counter service; eventual accuracy OK; do not lock video row per view.
Failure modes
| Mode | Impact | Mitigation |
|---|---|---|
| Transcode backlog | Long “processing” | Autoscale workers; priority lanes |
| Corrupt upload | Failed processing | Validate; user notify |
| CDN origin overload | Playback errors | Cache tuning; shield |
| Single processing region | Latency/cost | Multi-region processing later |
| Exact view counters | Write hotspot | Approximate/eventual counters |
Trade-offs
| Choice | Benefit | Cost |
|---|---|---|
| Many renditions | Quality UX | Encode + storage cost |
| Fewer renditions | Cheaper | Worse playback on poor networks |
| Sync processing | Simple | Terrible upload UX |
| Async processing | Scale | Delayed readiness |
Common mistakes
- App server streams every playback byte.
- No async pipeline.
- Perfect recommendation ML first.
- Strongly consistent global view count.
- Ignoring cost of egress and encoding.
Check your understanding
- Why presigned upload to object storage?
- What does a transcode worker output?
- How does ABR use playlists?
- Why eventual view counts?
- How do hot videos avoid melting origin?
Practice
- Estimate storage if 1M hours uploaded/day at multiple bitrates.
- Draw states: uploaded → processing → ready → failed.
- Design priority queue for paid creators.
- Discuss DRM at a high level (mention only).
- Mock interview.
Deeper production notes
Idempotent jobs
Processing must tolerate redelivery without spawning infinite duplicate renditions—content-addressed outputs help.
Cold storage
Move rarely watched originals to colder storage classes.
Additional teaching scenarios
Scenario A — 10× peak
Which component saturates first? First mitigation?Scenario B — dependency down 30 minutes
What still works? What degrades?Scenario C — interview wrap (5 sentences)
Requirements, MVP, main scale lever, key failure, top trade-off.Revision summary
- Upload → async process → CDN play.
- Metadata separate from media plane.
- Scale processing with queues/workers.
- Approximate counters for hot metrics.
Glossary
| Term | Definition |
|---|---|
| Transcoding | Re-encoding media into target formats. |
| ABR | Adaptive bitrate streaming. |
| Origin shield | Extra cache layer protecting origin. |
Abbreviations and terminology
- HLS — HTTP Live Streaming
- DASH — Dynamic Adaptive Streaming over HTTP
- CDN — Content Delivery Network
What to learn next
Extra teaching notes
When you apply this lesson, write the user-visible success metric first, then the failure mode you fear most. Design the smallest mechanism that protects that metric under partial failure. Prefer explicit timeouts, idempotency, and ownership over adding more infrastructure boxes.
In interviews or design reviews, narrate assumptions, request paths, and trade-offs out loud. A correct-enough design with clear failure handling beats a buzzword diagram without numbers. Revisit the worked example and restate it for a different domain to prove you own the ideas, not the template wording.
Extra teaching notes
When you apply this lesson, write the user-visible success metric first, then the failure mode you fear most. Design the smallest mechanism that protects that metric under partial failure. Prefer explicit timeouts, idempotency, and ownership over adding more infrastructure boxes.
In interviews or design reviews, narrate assumptions, request paths, and trade-offs out loud. A correct-enough design with clear failure handling beats a buzzword diagram without numbers. Revisit the worked example and restate it for a different domain to prove you own the ideas, not the template wording.
Extra teaching notes
When you apply this lesson, write the user-visible success metric first, then the failure mode you fear most. Design the smallest mechanism that protects that metric under partial failure. Prefer explicit timeouts, idempotency, and ownership over adding more infrastructure boxes.
In interviews or design reviews, narrate assumptions, request paths, and trade-offs out loud. A correct-enough design with clear failure handling beats a buzzword diagram without numbers. Revisit the worked example and restate it for a different domain to prove you own the ideas, not the template wording.
Extra teaching notes
When you apply this lesson, write the user-visible success metric first, then the failure mode you fear most. Design the smallest mechanism that protects that metric under partial failure. Prefer explicit timeouts, idempotency, and ownership over adding more infrastructure boxes.
In interviews or design reviews, narrate assumptions, request paths, and trade-offs out loud. A correct-enough design with clear failure handling beats a buzzword diagram without numbers. Revisit the worked example and restate it for a different domain to prove you own the ideas, not the template wording.
Extra teaching notes
When you apply this lesson, write the user-visible success metric first, then the failure mode you fear most. Design the smallest mechanism that protects that metric under partial failure. Prefer explicit timeouts, idempotency, and ownership over adding more infrastructure boxes.
In interviews or design reviews, narrate assumptions, request paths, and trade-offs out loud. A correct-enough design with clear failure handling beats a buzzword diagram without numbers. Revisit the worked example and restate it for a different domain to prove you own the ideas, not the template wording.
Interview and production field guide for this topic
Use this section as deliberate practice, not filler. Rewrite the worked example for a second domain you know well—fintech, education, logistics, or media. Keep the same skeleton: requirements, estimates, high-level diagram, request path, data model, scale lever, failure modes, and trade-offs. If you cannot fill every section without copying buzzwords, you do not yet own the design.
Numbers to force yourself to state
Always speak order-of-magnitude figures: peak QPS, storage growth per day, fan-out factor, connection counts, or queue depth. Wrong numbers that are explicit beat silent hand-waving. Correct the numbers when the interviewer or teammate challenges them; that is collaboration, not failure.
Failure minute
Set a timer for sixty seconds and list only failures: timeouts, duplicates, hot keys, dependency outages, bad deploys, and data corruption paths. For each, name detection and first mitigation. Designs that only describe the happy path are incomplete for production and weak in interviews.
Ownership and operability
Name the dashboard, the alert, the runbook section, and the team that pages. If any are blank, the system will train you during an incident. Prefer progressive delivery: canaries, flags, and rollback notes written before the change lands.
Consistency and retries
State whether the design assumes at-least-once delivery, whether handlers are idempotent, and where unique constraints live. Retries without idempotency are how double charges, double messages, and duplicate fan-out jobs appear. Timeouts without bounds are how thread pools die.
What good looks like in a review
A strong design review or interview answer clarifies scope, makes assumptions audible, draws a minimal path, deepens one or two bottlenecks, and closes with trade-offs and evolution. Use that bar on design-youtube round 0 every time you revisit it.
Interview and production field guide for this topic
Use this section as deliberate practice, not filler. Rewrite the worked example for a second domain you know well—fintech, education, logistics, or media. Keep the same skeleton: requirements, estimates, high-level diagram, request path, data model, scale lever, failure modes, and trade-offs. If you cannot fill every section without copying buzzwords, you do not yet own the design.
Numbers to force yourself to state
Always speak order-of-magnitude figures: peak QPS, storage growth per day, fan-out factor, connection counts, or queue depth. Wrong numbers that are explicit beat silent hand-waving. Correct the numbers when the interviewer or teammate challenges them; that is collaboration, not failure.
Failure minute
Set a timer for sixty seconds and list only failures: timeouts, duplicates, hot keys, dependency outages, bad deploys, and data corruption paths. For each, name detection and first mitigation. Designs that only describe the happy path are incomplete for production and weak in interviews.
Ownership and operability
Name the dashboard, the alert, the runbook section, and the team that pages. If any are blank, the system will train you during an incident. Prefer progressive delivery: canaries, flags, and rollback notes written before the change lands.
Consistency and retries
State whether the design assumes at-least-once delivery, whether handlers are idempotent, and where unique constraints live. Retries without idempotency are how double charges, double messages, and duplicate fan-out jobs appear. Timeouts without bounds are how thread pools die.
What good looks like in a review
A strong design review or interview answer clarifies scope, makes assumptions audible, draws a minimal path, deepens one or two bottlenecks, and closes with trade-offs and evolution. Use that bar on design-youtube round 1 every time you revisit it.
FAQ from first-time learners
Q: Where is the video “database”?
A: Bytes in object storage; metadata in DB; playback via CDN.
Q: Do I design codecs?
A: No—name requirements (multiple bitrates) and pipeline.
Track: Distributed Systems
Previous: Design WhatsApp — 1:1 and Group Messaging
By Shubham Jain