Skip to content

How to design YouTube

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Practice this question

The problem

A video platform takes in uploads and plays them back on phones, browsers and televisions. The two paths look nothing alike: about a million uploads a day averaging 300 MB, some running to tens of GB, against a hundred million views a day that each fetch small pieces of a video. The answer turns on keeping those paths apart. Uploads go in resumable chunks straight to blob storage, an asynchronous pipeline cuts each video into short segments and transcodes them into several qualities with a manifest, and a CDN serves the segments so the backend handles one small metadata read per view.

Clarifying questions

AskWhy it mattersA typical answer

How big are the uploads, and how many arrive a day?

The size decides whether a single request can carry a file at all, and the count decides how much transcoding capacity the pipeline needs.

About a million uploads a day. Videos average 300 MB, and some run to tens of GB, so an upload has to survive a dropped connection.

How many views a day, and on which devices?

The view count sizes the metadata path, and the device list decides how many formats and resolutions the pipeline has to produce.

About a hundred million views a day, on web, mobile and smart TVs.

Does playback need to adapt to the network, or is one fixed quality acceptable?

Adaptive playback means several renditions, short segments and a manifest; a fixed quality means a far simpler pipeline and a worse experience on a weak connection.

It has to adapt: a viewer on a train who keeps losing signal should keep watching, so the player must switch quality as bandwidth changes.

How soon after upload must a video be watchable?

Transcoding a 300 MB file takes real time, so the answer decides whether processing is asynchronous with a visible status, or whether playback has to start before processing finishes.

The prompt doesn't fix a number. Assume minutes rather than seconds: processing runs in the background and the uploader sees a status until the video is ready.

When something fails, do we prefer to keep serving or to be exactly right?

It tells you whether a slightly stale view count or a cached metadata record is acceptable in exchange for playback that stays up.

Availability wins. Our advice: keep play working while other parts are failing; metadata that lags by seconds is fine.

How much does delivery cost matter?

Serving video is the biggest bill in this system, and a cost target changes what you encode up front and what you keep on the CDN.

It matters. Plan around a CDN bill of about $0.02 per GB served, and be ready to say what you'd change to halve it.

Are search, comments, recommendations and moderation in scope?

Each is a system of its own, and the round is too short to carry them alongside the upload and playback paths.

No. Search, comments and view counts, recommendations, channels and subscriptions, and content moderation are all out of scope.

The requirements menu

RequirementScopeWhy

Upload a video

Core

The write path. Its shape (chunks, presigned URLs, an event when the file is complete) decides what the rest of the pipeline receives.

Stream a video on web, mobile and smart TVs

Core

The read path, and the one that carries nearly all the traffic. Several device types means several formats and resolutions.

Switch video quality as the network changes

Core

Forces short segments in several renditions and a manifest the player reads, instead of one file per quality.

Resume an upload that was cut off

Core

A file of tens of GB on a bad connection will drop at some point. Resuming means both sides have to know which pieces already arrived.

Show the uploader a processing status and a thumbnail

Optional

Cheap to add once the pipeline reports progress into metadata, and it shows you know processing is asynchronous. Skip it if the interviewer steers you to playback.

Resume playback where the viewer left off

Optional

A per-user, per-video position written by the player at intervals. Nice to mention because it rides on the metadata store, but it's not what the round is testing.

Deduplicate identical uploads

Optional

Chunk fingerprints give you the comparison; a global index of fingerprints and ownership checks are what make it a dedup store. Worth a sentence in the upload dive; the rest is a different system.

Private and unlisted videos

Optional

A visibility flag on the metadata plus signed playback URLs. Take it if asked; it changes how the CDN is allowed to cache.

Live streaming

Out of scope

The same segment and playlist format can carry it, but the pipeline becomes real-time and the latency budget changes everything. Name it and park it.

Search

Out of scope

An inverted index over titles and descriptions is its own system. Say that metadata changes would feed it, then stop.

Comments and view counts

Out of scope

High-write counters and threaded comments are separate problems; a view count in particular would be a hot key on the viral video.

Recommendations

Out of scope

A ranking pipeline over watch history. It consumes events this system could emit, and nothing more.

Channels and subscriptions

Out of scope

Ordinary relational data plus a fan-out on upload. Leave it unless asked.

Content moderation

Out of scope

Important in a real product, and a natural extra stage in the processing pipeline, but it needs classifiers and review tooling that don't fit the round.

Non-functional requirements

RequirementWhat it forces

Uploads of tens of GB

The file shouldn't pass through the API servers, and sending it as one request means a drop loses all of it. The client sends it in chunks to blob storage with a presigned URL, and something has to remember which chunks arrived so a drop doesn't restart the upload.

Playback starts fast, even on low bandwidth

The player needs a low-bitrate rendition to start on and short segments to switch between, served from an edge near the viewer. That means transcoding into several qualities before a video is marked ready.

About 1 million uploads and 100 million views a day (Hello Interview)

Roughly 12 uploads and 1,160 views a second. Uploads are rare but each one carries hundreds of megabytes and minutes of CPU; views are constant and tiny. The two paths get separate components that scale on their own.

Availability over consistency

Metadata can be cached and replicated with relaxed consistency: a view that reads a seconds-old record is fine. The one place this design insists on order is marking a video ready, which must happen after its segments and manifests exist.

Low delivery cost: CDN bills at about $0.02 per GB (Alex Xu)

Video bytes are the dominant cost, so what gets encoded, where it is stored and what the CDN keeps all become cost decisions. Popular videos earn their place on the CDN; rarely watched ones don't.

Estimates

QuantityWorkingResultWhat it sizes

Parts in a 10 GB upload

10 GB ÷ 5 MiB ≈ 1,900 parts (about 2,000); 10 GB ÷ 10 MiB ≈ 950 parts (about 1,000). S3 multipart allows up to 10,000 parts of 5 MiB to 5 GiB each, so parts at the 5 MiB minimum cover a file up to about 50 GB (10,000 × 5 MiB) before the client has to use bigger parts

1,000 to 2,000 parts for a 10 GB file; parts at S3's 5 MiB minimum reach about 50 GB before the part size has to grow

The chunk size. Parts of 5 to 10 MiB (the interviewer's 5 to 10 MB, rounded up to S3's minimum) are small enough that a dropped connection loses little and large enough to stay within the part limit for the uploads this design plans for.

Time to upload 10 GB on hotel wifi

Assume 20 Mbps upstream (an example figure, not a given): 10 GB = 80,000 Mb; 80,000 ÷ 20 = 4,000 s, about 67 minutes. One 10 MB chunk is 80 Mb; 80 ÷ 20 = 4 s

About 67 minutes for the file; about 4 seconds per 10 MB chunk

What one dropped connection costs: redoing the whole file is about an hour; redoing the chunk in flight is a few seconds.

Upload bytes a day

1 million uploads × 300 MB = 300 TB a day; 300 TB ÷ 86,400 s ≈ 3.5 GB/s, about 28 Gbit/s sustained

About 300 TB a day, 3.5 GB/s around the clock

Why upload bytes bypass the API servers: that stream flows directly into blob storage, and the service handles a few small calls per upload instead.

Originals stored a year

300 TB a day × 365 ≈ 110 PB a year at Hello Interview's upload rate; the alternative figure of 150 TB a day gives about 55 PB. Transcoded renditions come on top

Roughly 55 to 110 PB a year before any renditions

The storage side of the long tail: with viewing concentrated on a few videos, a large share of this volume sees few views, which is why rarely watched renditions belong on cheaper storage or aren't made until someone asks.

Transcoding fleet (an example to show the method)

Assume one core spends about 30 minutes to produce all renditions of an average 300 MB video. 1 million × 30 min = 30 million core-minutes a day = 500,000 core-hours; ÷ 24 ≈ 20,800 cores busy all day. A burst at three times the average rate wants about 62,500 cores for its duration

About 20,800 cores at the average rate; about 62,500 during a threefold burst

How many transcoding workers to run. Sizing near the average and letting a queue hold the burst is far cheaper than sizing for the peak.

Metadata reads landing on one viral video

100 million views a day ÷ 86,400 ≈ 1,160 reads a second overall. If, as an example, 60% of the day's views are the viral video, about 700 reads a second hit the one partition that owns its id and about 460 are spread over everything else

About 700 reads a second on one partition, against 460 for the rest of the catalog

The hot partition. The total is modest; the trouble is where it lands.

CDN bill at the view count, and what halving it saves

100 million views × 300 MB = 30 PB a day if each view pulled a full average-sized video; 30 PB × $0.02 per GB = $600,000 a day. The alternative figure of 25 million views gives $150,000. Halving the serving cost at the larger figure saves about $300,000 a day

Up to about $600,000 a day; halving it is worth about $300,000 a day

The cost curveball. Real views pull one rendition's segments and often stop early, so this is an upper bound, but it shows why the long tail should not sit on the CDN.

Core entities

EntityWhat it holds

User

Whoever uploads or watches. Accounts are out of scope, so this stays a stub that videos point at.

Video

The bytes: one original object in blob storage, then a set of segments per rendition once processing finishes.

Video metadata

One row per video: who owns it, where processing stands, which upload chunks have arrived and where the manifest lives.

Upload chunk

One entry per part of an in-flight upload; lives inside the metadata row or a side table keyed by video id.

The API

EndpointNotes

POST /presigned_url { metadata } → { upload_url }

Creates the metadata row with status uploading, starts a multipart upload in the blob store and returns a presigned URL (or one per part) that lets the client write to that one object. In this design the response also carries the video id, so later calls can reference it.

PATCH /videos/{id}/chunks { part_number, etag } → marks a chunk uploaded

The client calls this after each part lands. The service records the part and its ETag; before trusting it, it checks the part against the blob store's own list of uploaded parts. Idempotent, so a retried call after a drop is harmless. When the last part is in, the service completes the multipart upload.

GET /videos/{id} → metadata with the manifest URL for playback

The one backend call per view. Reads through the metadata cache; returns the primary manifest URL when status is ready, and the status otherwise so the client can show processing. Video bytes don't come through this call.

The high-level design

chunksUploaderVideo serviceMetadata DBS3 originals

Step 1 of 4

Uploads go straight to storage

Start with the write path. The client sends metadata to a stateless video service, which writes a row with status uploading and hands back a presigned URL for blob storage. The client then sends the video bytes to storage directly, in multipart chunks, and reports each part to the service, which records it in the metadata row. Nothing heavy passes through the service: at a million uploads a day of 300 MB, the raw stream is about 3.5 GB/s, and that goes to blob storage rather than to your servers.

metadata, ETagswritereadmissmultipart chunkscomplete eventsegment jobsmark readyGET /videos/idmanifest,segmentsUploaderVideo serviceMetadata DB, byvideo idMetadata cacheS3 originalsProcessing queueOrchestratorTranscodeworkersSegments,manifestsCDNPlayer
The whole design

What breaks first

The deep dives

Large, resumable uploads. Someone is uploading a file of tens of GB over hotel wifi and the connection drops halfway. What does the client send when it reconnects, what does each side have to remember, and what does the drop cost?

A concept that helps here: Chunked and resumable uploadsA concept that helps here: Blob storage and presigned uploadsA concept that helps here: Idempotency keys

Transcoding and adaptive streaming. A viewer on a train keeps losing signal and the video should keep playing. What did the pipeline produce from the upload, how does the player use it, and what changes when the serving bill has to be cut in half?

A concept that helps here: Transcoding and adaptive streamingA concept that helps here: Backpressure and load sheddingA concept that helps here: Retries and dead-letter queues

Scaling metadata and hot videos. One video goes viral overnight and most of the day's views ask for it. What does each part of the design see, where does the load concentrate, and what stops a viewer from being handed a video that isn't fully there?

A concept that helps here: Hot keys and hot partitionsA concept that helps here: Caching strategiesA concept that helps here: Replication and read replicas

Concepts this guide uses

Sources

  1. Alex Xu, System Design Interview, chapter 15: Design YouTube (book notes on books.dwf.dev)
  2. ByteByteGo: Design YouTube (System Design Interview course)
  3. Amazon S3 User Guide: Multipart upload limits
  4. Apple Developer: About HTTP Live Streaming
  5. Amazon S3 Developer Guide: Configuring Amazon S3 event notifications
Sign in to report a mistake