Design YouTube (video upload and streaming)
Let anyone upload huge video files and let billions watch them smoothly on any connection. The interesting parts: never moving video through your app servers, a transcoding pipeline, adaptive streaming over a CDN, and metadata that is read far more than it's written.
In one sentence
Upload straight to object storage, transcode asynchronously into many resolutions, stream small segments from a CDN, and keep metadata in a cached, replicated (later sharded) database.
A reference design: it covers what an app like this needs and follows how these companies have described their systems publicly, simplified to be learnable.
Requirements
Functional
- Upload videos (up to several GB)
- Watch videos on web, mobile and TV
- Search, comments, likes, view counts
- Personalized home feed
Non-functional
- Playback starts fast and doesn't buffer
- Uploads never get lost; processing can take minutes
- Massively read-heavy: views ≫ uploads
- Bandwidth and storage are the dominant costs
Back-of-the-envelope estimates
| Metric | Estimate |
|---|---|
| Daily active users | 1B, watching ~5 videos/day → 5B views/day ≈ 58K views/s |
| Uploads | 500 hours of video per minute (YouTube's public figure) |
| Storage per upload | 1 hour ≈ 1–3 GB original + all renditions (~2× more) |
| Egress | 58K concurrent-ish streams × ~3 Mbps ≈ hundreds of Tbps at peak: only a CDN can do this |
API and data model
POST /videos { title, sizeBytes } → { videoId, uploadUrl }
PUT {uploadUrl} (multipart, resumable, straight to storage)
GET /videos/:id → { title, channel, manifestUrl, stats }
GET /feed?cursor=… → [ videoCard ]
GET /search?q=…
videos(id, channel_id, title, status, duration, created_at)
renditions(video_id, resolution, manifest_path)
views_daily(video_id, day, count) -- aggregated asynchronouslyArchitecture
Two separate paths: the upload pipeline (write, slow, asynchronous) and the watch path (read, latency-critical, mostly CDN). Follow both below.
Step by step · Upload a video
- 01Creator picks a 2 GB file
- 02POST /videos (title, size)
- 03Creates the video row and a pre-signed URL
- 04File uploaded in parts, straight to the bucket
- 05"video 42 uploaded" job enqueued
- 06Produces 240p…4K HLS segments and thumbnails
- 07Renditions saved next to the original
- 08Status = ready; search index updated
- 09"Your video is live" notification
At this scale · 1M users
Services around the video lifecycle
- ▸Upload service gives clients pre-signed URLs to upload straight to storage
- ▸Adaptive streaming (HLS/DASH) in several resolutions
- ▸Search index and precomputed recommendations
- ▸Metadata in MySQL with read replicas
Tap any box to see what it does.
Deep dive: transcoding and adaptive streaming
A phone on 3G and a 4K TV can't watch the same file. Each upload is transcoded into several renditions (240p, 480p, 720p, 1080p, 4K) and cut into segments of a few seconds with a manifest (HLS or DASH). The player measures bandwidth and picks the best quality for the next segment.
- Transcoding is CPU-heavy and slow, so it runs in workers fed by a queue: uploads never wait for it.
- At scale the original is split into chunks and transcoded in parallel, then stitched: a 2-hour video is ready in minutes.
- Segments are immutable files, perfect for CDN caching. Popular videos live in edge caches; YouTube also places caches inside ISPs.
- Uploads use pre-signed URLs and multipart upload: app servers never touch the gigabytes, and a dropped connection resumes.
Deep dive: view counts and recommendations
Writing views = views + 1 58K times per second on hot rows would melt the database. Views are events sent to a queue, aggregated in batches and written periodically; the page shows a cached, slightly delayed number.
Recommendations are precomputed: offline jobs produce candidate videos per user from watch history, and a fast ranking step orders them per request.
How it changes with scale
Step by step · Watch a video
- 01Opens youtube.com/watch?v=42
- 02Reads title, channel and file URL
- 03Cache miss: read the database
- 04Player downloads the HLS manifest
- 05Small scale: segments straight from the bucket
- 06Plays; a view event is sent asynchronously
At this scale · 100 users
A server, a database and a bucket
- ▸Videos go to object storage (S3), never to the database
- ▸A background job on the same server transcodes with ffmpeg
- ▸Video files are served straight from the bucket
Tap any box to see what it does.
| Users | What you run | Why it changes |
|---|---|---|
| 100 | App + PostgreSQL + S3, ffmpeg in a background job | Simple and cheap; storage is already the right place for files |
| 10K | CDN, transcode queue + workers, Redis | Bandwidth costs and slow transcodes blocking the app |
| 1M | Upload / video / search / recommendation services, HLS, MySQL replicas | Different parts scale differently; reads dominate |
| 100M+ | Sharded metadata (Vitess), ISP caches, parallel chunked transcoding, ML | Global egress, billions of rows, petabytes of video |
Key takeaways
- 01Never stream big files through app servers: object storage for uploads, CDN for playback.
- 02Transcoding is an asynchronous pipeline behind a queue.
- 03Adaptive streaming = many renditions × small segments + a manifest.
- 04View counts are events aggregated in batches; recommendations are precomputed.
Check your understanding
1 of 3
In a video platform like YouTube, where should a video upload go?