Skip to content

Design YouTube

A system design interview walkthrough for a video platform like YouTube, covering resumable uploads, a chunked transcoding pipeline and scalable view counting.

Advanced22 minUpdated 2 December 2026

Before this: Content Delivery Network (CDN), Message Queues, Batch vs Stream Processing

"Design YouTube" is really three questions in a trench coat: how do you take in huge files reliably, how do you turn one file into many that every device can play, and how do you count a number that millions of people are incrementing at once? Candidates who spend 40 minutes on the video player and the home page miss all three.

The interviewer wants to hear you separate the upload and processing path, which is write-heavy, slow and asynchronous, from the playback path, which is read-heavy, latency-sensitive and almost entirely a CDN job. They then pick one hard part from each. This page goes deep on resumable upload, the transcoding pipeline and view counting.

Adaptive-bitrate playback, edge caching and how a player chooses a quality are the subject of Design Netflix. Here we meet playback only as the reason we transcode.

Clarify the requirements

Functional requirements:

  1. A creator uploads a video (up to several GB), with a title and description.
  2. After processing, anyone can watch it on any device and network.
  3. Videos show a view count, and creators see aggregated analytics.
  4. Search and browse by title and channel.
  5. Thumbnails are generated automatically.

Out of scope, said aloud: recommendations and the home feed (see Design TikTok for a ranked feed), comments, live streaming, monetization, copyright matching (name it as a follow-up).

Non-functional requirements: these decide the architecture.

  • Uploads are reliable and resumable. A 2 GB upload on a mobile connection will be interrupted. It must continue, not restart.
  • Playback starts fast and rarely stalls, on devices from a phone on 3G to a 4K television.
  • Processing is eventually done, not instant. A video can take minutes to appear, but it must never be lost or processed twice into two different videos.
  • Views are counted approximately and quickly, exactly later. A displayed count a minute old is fine.
  • Storage and egress dominate cost. The design should push as much traffic as possible onto the CDN and as little as possible onto the origin.

Estimate the scale

Assume 500 million daily active users. Each watches about 5 videos a day. Assume 2 million videos are uploaded a day, averaging 5 minutes and 100 MB as originally uploaded.

Uploads: 2M ÷ 86,400 ≈ 23 per second on average, about 70 per second at peak. Small in number, huge in bytes.

Upload bytes: 2M × 100 MB = 200 TB a day, or about 73 PB a year of originals.

Stored renditions: each video is transcoded into a ladder of about six resolutions and bitrates. Together they take about as much space again as the original, so storage is roughly 2x: about 400 TB a day, or 145 PB a year.

Transcode compute: 2M videos × 300 s = 600 million seconds of video a day. If each rendition takes about one core-second per second of video, six renditions cost 3.6 billion core-seconds a day. Divided by 86,400 that is about 42,000 cores running around the clock.

Views: 500M × 5 = 2.5 billion a day, about 29,000 view starts per second, and about 87,000 per second at peak.

Playback bandwidth: with an average of 30 minutes watched per user per day, concurrency is 500M × 1,800 s ÷ 86,400 ≈ 10 million simultaneous streams. At about 3 Mbps each, that is roughly 30 Tbps, nearly all of it from CDN edges.

"23 uploads a second is nothing, but each one is 100 MB and triggers 180 pieces of compute work. 87,000 view starts a second is a counting problem. And 30 Tbps can only be served by a CDN. So the three hard parts are a durable upload path, a parallel transcoding pipeline and a counter that does not become a hot row."

You can reproduce the upload rate and the 73 PB figure in the capacity estimator.

API and data model

POST /v1/uploads                  { title, size, contentType } -> { uploadId, partUrls[] }
PUT  <part url>                   (bytes, direct to object storage)
POST /v1/uploads/{id}/complete    { etags[] }                  -> { videoId, status: processing }
GET  /v1/videos/{id}                                           -> metadata + manifest URL
GET  /v1/videos/{id}/manifest.m3u8 | .mpd                      (served by the CDN)
POST /v1/videos/{id}/view         { sessionId, watchedMs }
videos     (video_id PK, channel_id, title, status, duration, created_at)
renditions (video_id PK, profile CK, object_key, bitrate, state)
view_counts (video_id PK, bucket CK, count)       -- sharded counter
objects    S3-style: raw/<uploadId>, segments/<videoId>/<profile>/<n>.ts

The non-obvious choice: the bytes never pass through the API servers. The API hands out pre-signed URLs for each part, and the client uploads straight to object storage. The API only starts and finishes the upload.

High-level design

We simulate the ingest side: the API accepts uploads and writes metadata, raw files land in object storage, an event announces each upload on a stream, and a transcoding fleet reads the stream and writes renditions back to storage.

An upload API stores raw video in S3 and metadata in Postgres, then publishes a job to Kafka, where a transcoding fleet reads it and writes renditions back.creatorsupload apivideo objectsvideo metadataupload eventstranscoder fleet
An upload API stores raw video in S3 and metadata in Postgres, then publishes a job to Kafka, where a transcoding fleet reads it and writes renditions back.
  • The upload API stores metadata, hands uploads to object storage and publishes a job event.
  • A transcoder fleet consumes jobs from Kafka and writes the finished renditions back to storage.
Describe this diagram

Components

  • creators (Client)
  • upload api (Service)
  • video objects (Object storage (S3))
  • video metadata (PostgreSQL)
  • upload events (Kafka)
  • transcoder fleet (Service)

Connections

  • creators sends to upload api
  • upload api sends to video objects
  • upload api sends to video metadata
  • upload api sends to upload events
  • upload events sends to transcoder fleet
  • transcoder fleet sends to video objects

Run it, then try cutting the transcoder instances or raising the load. A growing backlog on the stream is the signal that processing has fallen behind.

The upload path: the creator's app asks for an upload, uploads parts in parallel straight to object storage, and calls complete. The API marks the video processing and publishes a video.uploaded event.

The processing path: the pipeline validates the file, splits it, transcodes the pieces in parallel, packages them into streaming segments with a manifest, generates thumbnails and flips the video to ready.

The interesting problem: the transcoding pipeline

Turning one upload into a ladder of renditions is a large, parallelizable, failure-prone job.

Approach A: one worker transcodes the whole file

A worker takes the upload, runs every rendition sequentially, writes the output and finishes.

Good: simple, one unit of work, easy to reason about.

Bad: a 2-hour film takes hours on one machine, and a crash at 95% restarts from zero. A few huge uploads block a worker that should be serving many small ones. Latency to "ready" is the full encode time.

Approach B: split into chunks, transcode in parallel, stitch

Cut the video at keyframe-aligned boundaries into segments of about 10 seconds, so each segment can be encoded independently. Create one task per (segment, rendition). Run them on a fleet, then assemble the results and write a manifest listing every segment.

Good: a 300-second video becomes 30 segments x 6 renditions = 180 small tasks that run in parallel, so time to ready is closer to the encode time of one segment than the whole video. A failed task retries alone. Capacity scales by adding workers.

Bad: more orchestration. You need to track the state of 180 tasks, handle stragglers, and make sure the stitch happens exactly once. Segment boundaries need care so rate control and audio stay smooth.

Approach C: B with a priority-aware, idempotent task graph

Model the pipeline as a graph of stages: validate, split, encode segments (fan-out), package (fan-in), thumbnails, publish. Put tasks on a priority queue, so short clips and first uploads go first. Make every task idempotent: its output path is derived from (videoId, profile, segment), so running it twice overwrites the same object and the second run is harmless. The package step runs when the finished-segment count equals the expected count.

The recommended design is C. The key phrases are chunk, fan out, fan in and idempotent tasks, plus a dead letter queue for files that fail repeatedly (corrupt or hostile input), so one bad upload never blocks the line.

The second decision: counting views

A view count looks like a trivial integer. At 29,000 views a second on average and 87,000 at peak, with some videos taking thousands a second, it is not.

The naive way: UPDATE videos SET views = views + 1. Every view takes a row lock on a hot row. A viral video turns one row into a serialization point, and the database falls over long before the CDN notices.

Event first, counter second. The player sends a view event after a meaningful threshold, for example 30 seconds watched, which is also the first defense against inflated counts. Events go to a stream (see stream processing). A stream job counts them in tumbling windows of a few seconds per video, and writes one batched increment per video per window to a counter store. A hot video then receives one write every few seconds instead of thousands a second. The counter is also sharded into buckets that are summed on read.

Fraud and exactness. A second pipeline deduplicates events, filters bots and recomputes authoritative counts in batch. The page shows the fast number, and analytics use the reconciled one.

Bottlenecks and failures

A backlog on the transcode queue. After a big event, uploads spike and the queue grows. Autoscale workers on queue depth, protect priority lanes so short and first-time uploads are not stuck behind long ones, and tell the creator the expected wait honestly.

Stragglers. In a fan-out of 180 tasks, the slowest one decides when the video is ready. Detect tasks running much longer than their siblings and launch a duplicate. Idempotent outputs make that safe.

A bad file. Corrupt or malicious input must not crash the fleet. Run encoders in sandboxed workers with time and memory limits, validate containers first, and send repeated failures to a dead letter queue with the video marked failed.

Hot videos on the CDN. A viral new video is requested everywhere before any edge holds it. Use an origin shield so thousands of edges miss against one mid-tier cache, not storage (see the CDN lesson).

What if the transcoding fleet is down? Uploads still succeed and queue. Videos stay in processing longer, but nothing is lost, which is the reason the stream sits between upload and encode.

Trade-offs to name aloud

  • Direct-to-storage uploads: the API stays small and cheap, but upload progress and validation rely on callbacks and checks after the fact.
  • Chunked parallel transcoding: fast time-to-ready, at the cost of orchestration state and stitch logic.
  • Windowed, sharded view counters: the display lags by seconds, in exchange for no hot row.

What interviewers listen for

  • A working answer: upload to object storage, a queue, transcoding workers, a CDN for playback and a metadata database.
  • A strong answer: pre-signed multipart upload so bytes skip the API, chunked parallel transcoding with idempotent tasks and a dead letter queue, and a stream-based counter instead of a row increment.
  • A standout answer: also sizes compute from video-seconds, publishes a low rendition first, prioritizes tasks, detects stragglers, discusses sandboxing untrusted media, separates displayed from reconciled view counts and uses an origin shield for a viral launch.

Check your understanding

Common mistakes

Transcoding the whole file in one task. It is slow, wasteful on failure and monopolizes a worker. Chunk the work.

No plan for poison inputs. A malformed file can crash encoders again and again. You need sandboxing, a retry limit and a dead letter queue.

Incrementing a counter per view in the main database. It is the classic hot-row failure. Name the stream, the window and the sharded counter.

Forgetting cost. At 145 PB a year of renditions, storage tiering and lazy encoding of rare qualities are not details. They decide whether the product is viable.

Practice

A 3-hour 4K conference recording is uploaded. It would take about 6 hours to encode on one worker. How does your pipeline handle it, and what does the creator see?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Do the arithmetic on chunks, then decide in what order qualities should become available.

Show a strong answer

Chunk it. At 10-second segments, 3 hours is 1,080 segments. With 6 renditions that is 6,480 tasks. On 500 workers at once, each task taking around a minute, the encode finishes in roughly 6,480 ÷ 500 × 1 minute, about 13 minutes, instead of 6 hours.

Order the work so something is playable early. Encode the lowest rendition for all segments first, and mark the video ready at 360p as soon as that rendition is complete, which here is around 2 minutes. Higher qualities arrive over the next few minutes, and the manifest is updated as they do.

The pattern worth keeping: chunking turns a long job into many short ones, which improves latency, retry cost and fairness together.

Creators complain that the view count on their video lags by several minutes during a viral spike. Where could the delay come from, and how would you find and fix it?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Walk the view event along its whole path and look for a place where work can queue.

Show a strong answer

Follow the event. Player to view API, to the stream, to the windowed counter job, to the counter store, to the cache that serves the page. Each hop can add delay. Measure the age of the newest event at each stage, which is the same as monitoring the consumer lag.

Likely cause one: stream lag. If the partitions are keyed by video_id, a viral video puts all its events on one partition and one consumer, which cannot keep up. Fix it by adding a random sub-key, spreading the video's events over several partitions, and merging the partial counts downstream.

Likely cause two: cache TTL. The page may read the count from a cache with a long TTL. For hot videos, shorten the TTL or refresh the cache when a new batched increment lands.

The pattern worth keeping: when a pipeline lags, measure the age of data at every hop, then relieve the one hot key that owns the backlog.

Key takeaways

  • There are three hard problems: the upload path, the transcoding pipeline and view counting.
  • Upload directly to object storage with pre-signed, resumable multipart parts.
  • Chunk, fan out and fan in, with idempotent tasks, priorities and a dead letter queue.
  • Make something playable early by publishing the lowest rendition first.
  • Count views from a stream in windows, into sharded counters, and reconcile in batch.
  • Let the CDN carry playback (30 Tbps) and use an origin shield for the viral launch.

Further reading

  • R. Pantos and W. May, RFC 8216 "HTTP Live Streaming" (2017): the manifest and segment model that transcoded output is packaged into.
  • J. Dean and S. Ghemawat, "MapReduce: Simplified Data Processing on Large Clusters", OSDI (2004): the split, map and reduce shape that chunked transcoding follows.
  • J. Kreps, N. Narkhede and J. Rao, "Kafka: a Distributed Messaging System for Log Processing", NetDB workshop (2011): the log that carries job and view events.

Check yourself

3 questions in this lesson. Answer each once to complete it.

Practice this

Lessons in this track