Design YouTube: the video streaming system design walkthrough
How the video streaming round is actually run
The request to design YouTube sounds like a two-table CRUD app - upload a file, save it, let people press play. For one video and one viewer that is exactly what it is.
But the interview asks you to do it for a billion viewers watching on everything from a gigabit fibre line to a phone on a dropping 3G signal, with playback that starts in under two seconds and never buffers if it can help it - and that is a delivery and encoding problem, not an upload form.
This is one of the most common video streaming system design prompts because the one-line brief hides a transcoding pipeline, a global CDN, and a read path that is thousands of times heavier than the write path.
The round turns on two realities. First, the file a creator uploads is almost never the file a viewer plays: it must be re-encoded into a ladder of resolutions and bitrates so the player can switch on the fly as the network changes.
Second, when you design a video streaming service at this scale, the bytes do not flow from your servers at all - they flow from edge caches close to the viewer, and your job is to keep the right segments warm in those caches.
This walkthrough follows the path a strong candidate draws on the whiteboard - requirements, estimate, API and data model, high-level design, then the deep dives - and at each step it names the follow-up the interviewer uses to tell a memorised answer from an engineer who understands the tradeoff.
A video streaming round runs about 60 minutes on a shared canvas - you draw the boxes and arrows while you talk, and the interviewer interrupts.
It is a favourite because the one-line problem opens onto deep water fast: the moment you write "store the video and stream it," the question becomes in what formats, from where, and how does playback adapt when the network changes - and every answer after that (transcoding, packaging, CDN, adaptive bitrate) compounds.
Get the transcode pipeline and the delivery path clean and you have shown the whole system in one problem.
The interviewer rarely lets "upload the file and serve it back" stand. "The viewer is on a train, their bandwidth drops to almost nothing mid-video - what happens to their playback?"
That question - graceful degradation under a design that is otherwise just a file server - is the one a copied answer can never rehearse, and the one this round is really testing.
The rounds here are modelled on how the loop runs, not scraped from any candidate's recall. What matters for prep is the shape: a blank canvas, a clock, and a follow-up after every decision you make.
The five-step framework for any HLD round
Every high-level design answer fits the same spine. Say it out loud at the start so the interviewer knows you have a plan, then walk it:
- Clarify requirements - functional and non-functional, and what you are explicitly not building.
- Estimate - uploads, storage and read:write ratio, to justify every later choice.
- High-level design - the boxes and arrows: client, upload service, blob store, transcoding pipeline, CDN, player.
- Deep dive - the two or three decisions that actually decide this system.
- Follow-ups - bottlenecks, failure modes, and what you would change at ten times the scale.
What the debrief measures
The score is not "right or wrong design." A good HLD debrief reads on four dimensions, and every move below maps to one: problem solving (did you make the transcode pipeline chunked so it parallelises, and the view count asynchronous so a viral spike cannot melt the database), communication (did you say why you serve from a CDN and not from origin in a sentence), technical execution (ABR with an HLS/DASH manifest, segment caching at the edge, an approximate-then-reconcile view counter), and time management (did you spend your 60 minutes on transcoding and delivery, not on the upload button).
Reading a walkthrough teaches the design; it does not teach you to deliver it on the clock while someone pushes back.
Step 1 - Requirements: what YouTube must do
Spend the first few minutes here. Jumping to boxes before you have scoped the problem is the fastest way to design the wrong system.
- Functional: Upload a video; transcode it into multiple resolutions and bitrates; store it durably; stream it on demand to any device; let viewers see a view count; show basic metadata (title, channel, thumbnail).
- Functional (optional): Search, recommendations, comments, likes, subscriptions, live streaming - name them, then scope them out so you can go deep on upload-transcode-deliver.
- Non-functional: Massive read scale (reads dwarf writes by orders of magnitude); low startup latency (playback begins in ~1-2s); high availability and durability (an uploaded video is never lost); global reach (viewers on every continent and every network speed).
The sentence that earns points: "The upload is the easy part - the system is really a transcoding pipeline feeding a global CDN, and the read path is thousands of times heavier than the write path."
Say that and you have framed the entire design before drawing a box.
Step 2 - Capacity estimation (back of the envelope)
Estimation here is about proving one thing: the hard axis is transcoding and CDN delivery on a read-heavy workload, not the upload throughput.
- Upload rate: ~500 hours of video uploaded/min - a continuous, write-heavy transcode queue, not a spike
- Read:write ratio: views vastly outnumber uploads ~1000:1 or higher โ the system is a read/delivery system
- Storage: raw + every rendition, retained petabytes, growing forever โ object storage, tiered by popularity
- Egress: every view streams segments dominated by the CDN, not origin โ bandwidth lives at the edge
Two conclusions fall out, and you should say both out loud.
First, this is a read-and-deliver system - the write path (upload) is a steady queue you can process offline, but the read path serves orders of magnitude more traffic, so it must be cached at the edge and never hit origin for a popular video.
Second, the transcode is the expensive write-time work - one upload fans out into many renditions, so you parallelise it rather than encode a two-hour film on one machine.
You have now pointed the interview at the real deep dives before anyone asked.
Step 3 - API and data model
Two interfaces matter: the upload path (client โ your servers) and the playback path (player โ manifest โ CDN). The tables hold metadata and view state; the video bytes live in object storage.
POST /videosโupload_url- request a resumable, chunked upload (a presigned URL into blob storage)PUT {upload_url}(chunked) - upload raw bytes in resumable chunks, so a dropped connection resumes, not restartsGET /videos/{id}โmanifest_url+ metadata - fetch the HLS/DASH manifest URL and title/channel/thumbnail for playbackPOST /videos/{id}/view- record a view event (fire-and-forget, aggregated asynchronously)
The data model is thin - most of the system's weight is in object storage and the CDN, not the database:
video_metadata-video_id,title,channel_id,status(uploaded/transcoding/ready),duration,thumbnail_url,created_at.rendition-video_id,resolution,bitrate,codec,segment_path- one row per rendition in the bitrate ladder.manifest- the HLS/DASH playlist that lists every rendition and its segments, so the player can pick and switch.view_store- an append-only stream of view events plus aview_countper video, aggregated in batches.
Step 4 - High-level design: upload, transcode, deliver
Now the boxes. The system splits cleanly into a write path that prepares the video and a read path that delivers it. Draw them as two flows meeting at object storage:
- Client โ Upload service โ raw blob store: the client requests a presigned, chunked/resumable upload and pushes the raw file straight into object storage - the upload service never buffers the whole file.
- Transcoding pipeline: triggered when the raw upload lands; it splits the video into chunks, encodes each chunk into every rung of the bitrate ladder (e.g. 240p โ 1080p โ 4K) in parallel, then packages the renditions into HLS/DASH segments and writes a manifest.
- Object storage โ CDN: the transcoded segments and manifest are stored once and pushed out to CDN edge nodes close to viewers.
- Player โ manifest โ CDN: the player fetches the manifest, then streams segments from the nearest edge, switching renditions on the fly - adaptive bitrate streaming.
- Metadata DB + view pipeline: a metadata service answers "what is this video" and a separate asynchronous pipeline counts views without touching the playback path.
Say explicitly that the bytes never flow from origin for a popular video - the write path prepares segments once, and every view after that is served from the edge cache.
Naming that split (prepare once, deliver many times, from the edge) unprompted is a signal the interviewer is listening for.
Deep dive: the video transcoding pipeline
This is the first decision that actually decides the round. A naive design transcodes the whole file on one worker - a two-hour 4K upload would take hours and pin a machine the entire time, and if that worker dies at 90% you start over.
The senior answer chunks the video and treats transcoding as a parallel pipeline.
- Split: break the raw video into short segments (a few seconds each) at keyframe boundaries - So each chunk can be encoded independently, in parallel, on a different worker.
- Encode (fan-out): for every chunk, encode it into every rung of the bitrate ladder - a DAG of independent encode jobs - So one upload becomes many renditions fast, and a failed chunk is just one small job to retry.
- Package & stitch: assemble the encoded chunks into per-rendition HLS/DASH segments and write the manifest - So the player gets a single playlist describing every rendition and its segments.
The win is threefold: parallelism (hundreds of chunks encode at once instead of one long serial job), fault tolerance (a crashed worker re-runs one chunk, not the whole film), and faster time-to-ready (short videos can start publishing early renditions while longer work continues).
Chunk-level encoding is why a long upload can be "ready" in minutes, not hours.
"Why transcode in chunks instead of just encoding the whole file?" Chunking turns one long serial job into hundreds of parallel ones, so a two-hour video is ready in minutes; and when a worker dies you retry a three-second chunk, not the entire encode. Name both the speed and the fault-tolerance half.
System Design HLD ยท Media & analytics ยท 60 min Design the transcoding pipeline out loud, with follow-ups Practise on Zynter โ
Deep dive: adaptive bitrate streaming and CDN delivery
This is the decision most candidates under-think. The online path looks easy - "the player downloads the video" - but the follow-ups are always "what happens when the network changes?" and "where do the bytes actually come from?"
Adaptive bitrate streaming (ABR). The player never downloads one fixed-quality file. It fetches a manifest (HLS .m3u8 or DASH .mpd) that lists every rendition in the ladder, each cut into short segments.
The player downloads a few seconds at a time, measures the throughput it just got, and picks the next segment's quality to match - stepping down to 480p when bandwidth drops so playback keeps running, stepping back up when it recovers.
Buffering becomes a rare worst case, not the default, because the player degrades quality instead of stalling.
CDN delivery. Those segments are served from CDN edge nodes, not your origin. A viewer requests the nearest edge; if the segment is cached there (a cache hit) it never touches your servers.
The whole read path lives or dies on the cache-hit ratio - a popular video should be served almost entirely from the edge. For a known-viral release you pre-warm the popular renditions into edge caches before the traffic arrives, so the first million viewers already hit a warm cache.
Hot vs. long-tail. Popular videos stay hot at the edge; the long tail is fetched from origin on a cache miss and cached on the way out. Tier storage by popularity so you are not paying premium egress for videos nobody watches.
"The user is on mobile and their bandwidth drops mid-video - what happens?" ABR notices the lower throughput on the last segment and switches the next segment down to a lower rendition, so playback continues at reduced quality instead of buffering; it steps back up when the network recovers. Say the measure-then-switch loop, not just "it lowers quality."
System Design HLD ยท Media & analytics ยท 60 min Defend adaptive streaming and CDN caching out loud Practise on Zynter โ
Deep dive: view counts at scale and the read path
Scale changes the shape of the counter. A single UPDATE videos SET views = views + 1 per play is fine for a small site and a disaster for a video that goes viral - millions of writes a second to one hot row will melt the database.
The senior answer makes the count asynchronous and approximate, then reconciled.
- Write path: Naive - synchronous +1 on a hot row per view. Scaled - emit a view event to a stream (Kafka) and return immediately; playback never waits on the counter.
- Aggregation: Naive - count rows on read. Scaled - stream-aggregate events in small time windows and increment a cached counter in batches, flushing to the DB periodically.
- Hot videos: Naive - one row, one lock. Scaled - show an approximate count from cache (updated every few seconds) and reconcile the exact total offline - viewers do not need the number to be exact to the unit.
The same "serve from cache, reconcile in the background" idea runs the whole read path: video metadata (title, channel, thumbnail) is cached hard because it is read constantly and changes rarely, so a play request resolves metadata from cache and segments from the CDN, and almost never touches the primary database.
Repeat the real axis out lo
Comments
No comments yet. Start the discussion.