Design a video streaming platform (like YouTube)
Design a video streaming platform like YouTube: creators upload videos, the platform processes them, and viewers around the world watch them smoothly on any device and network.
A typical framing: "Creators upload 500 hours of video every minute. Viewers watch a billion hours a day on phones, TVs and laptops, on everything from fiber to weak mobile networks. Playback should start fast and rarely buffer."
TL;DR
Split the system into an upload and processing pipeline and a playback path.
- Upload: clients upload directly to object storage with resumable, chunked uploads (pre-signed URLs), so app servers never carry video bytes.
- Processing: a DAG of jobs on a worker fleet: validate, split into segments, transcode in parallel into a bitrate ladder (e.g. 240p to 4K, in H.264, VP9 and AV1), package for HLS/DASH, generate thumbnails and captions.
- Playback: the player downloads a manifest and then small segments (2 to 6 seconds) from a CDN, switching quality per segment based on measured bandwidth (adaptive bitrate).
Metadata (titles, owners, view counts) lives in a database with caches; view counts are aggregated asynchronously. Popular content is cached at the edge; the long tail is served from origin and cheaper storage tiers.
1. Requirements and estimates
Functional
- Upload videos (large files, unreliable networks), with title, description and visibility.
- Watch videos on any device with adaptive quality; seek anywhere.
- Video page metadata: views, likes, comments (comments can be out of scope).
Non-functional
- Fast start (under ~2 s) and minimal rebuffering worldwide.
- Uploads never lost; processing within minutes.
- Cost efficiency: storage and bandwidth dominate the bill.
Estimates
- Uploads: 500 hours / minute ≈ 720,000 hours / day. At ~1 GB per hour for the source file, ~720 TB / day of originals, more after transcoding into several renditions (often 2 to 3×).
- Watching: 1B hours / day; at an average 2 Mbps that's ~0.9 GB per hour → ~900 PB / day of egress. This is only realistic with a CDN serving the vast majority of bytes.
2. API
POST /v1/uploads { filename, sizeBytes, title } -> { uploadId, partUrls[] }
PUT <pre-signed part URL> (chunk bytes, retried per part)
POST /v1/uploads/{uploadId}/complete -> { videoId, status: "processing" }
GET /v1/videos/{id} -> metadata + manifest URL when ready
GET https://cdn.example/v/{id}/master.m3u8 -> HLS master manifest
GET https://cdn.example/v/{id}/720p/seg_00042.m4s -> one segment3. Data model
videos (id, owner_id, title, description, status, duration, visibility, created_at)
renditions (video_id, resolution, codec, bitrate, manifest_path)
upload_parts (upload_id, part_number, etag, status)
view_counts (video_id, count) -- aggregated from view events
object storage originals/{videoId}/source.mp4, renditions/{videoId}/{res}/seg_*.m4s4. High-level architecture
5. Deep dives and scaling
Resumable uploads
A 10 GB upload over a phone connection will be interrupted. Split it into parts (e.g. 8 to 64 MB), upload each to a pre-signed URL (S3 multipart upload), and track completed parts, so a retry only resends missing parts. Verify checksums and enforce size limits.
The processing pipeline
- Split, then transcode in parallel: cut the source into segments at keyframes and transcode each segment on a different worker; a 2-hour video finishes in minutes instead of hours.
- A workflow orchestrator (e.g. Temporal, Step Functions, or a custom DAG runner) tracks each step, retries failed tasks, and makes steps idempotent (output paths are deterministic, so rerunning overwrites safely).
- Prioritize: transcode the most-watched resolutions first so the video becomes playable quickly; produce expensive codecs (AV1) later, and only for videos that get popular.
- Also: thumbnails, audio normalization, automatic captions, content moderation and copyright matching.
Adaptive bitrate streaming
The master manifest lists renditions; each rendition has a playlist of segments. The player measures download speed and buffer level and picks the next segment's quality accordingly. Short segments allow faster switching; longer segments compress better and reduce request overhead.
CDN and storage cost
- Popularity is extremely skewed: a small fraction of videos makes up most views. Cache those at the edge, close to viewers (and, at YouTube or Netflix scale, inside ISPs' networks).
- The long tail is served from regional origin caches and object storage.
- Move old, rarely watched renditions to cheaper storage tiers, and drop renditions nobody watches (they can be regenerated from the original).
Metadata and view counts
Metadata is read-heavy: cache video pages aggressively. View counts would be a hot-row disaster if updated per view; instead, send view events to a stream, aggregate them in short windows, and update counts in batches. Counts can lag by seconds or minutes.
Security and access
Private and paid videos use signed URLs or tokens with short expiry for manifests and segments. Premium content uses DRM (Widevine, FairPlay, PlayReady).
Common follow-ups
- "How does seeking work?" The manifest maps time to segments; the player requests the segment that contains the target time, so it never downloads the whole file.
- "What changes for live streaming?" Ingest via RTMP, SRT or WebRTC; transcode in real time; publish segments as they're produced with a rolling manifest; low-latency HLS uses smaller partial segments. There's no time to transcode many codecs offline.
- "How do you avoid processing the same upload twice?" The upload-complete event carries the video id; the orchestrator starts a workflow with that id as its key, so duplicate events are ignored.
What interviewers look for
- Direct-to-storage, resumable uploads that keep app servers out of the data path.
- A parallel, idempotent transcoding pipeline with a bitrate ladder.
- Adaptive bitrate with HLS/DASH, and a clear role for the CDN.
- Cost awareness: storage tiers, popularity skew and egress.
- Asynchronous view counting and signed URLs for access control.