Design Problems · Video Streaming

Design a Video Streaming Service

From upload to playback: resumable uploads to object storage, a transcoding pipeline, adaptive bitrate streaming and global delivery through a CDN.

  • 9 min read
  • 9 practice questions
  • 1 graded problem
On this page
  1. Description
  2. The first version, and why it breaks
  3. The numbers
  4. Uploading
  5. The transcoding pipeline
  6. Adaptive bitrate streaming
  7. Delivery
  8. Metadata and storage tiers
  9. Which piece solves what
  10. Common mistakes
  11. Check yourself
  12. Key takeaways
  13. Quick revise
  14. Practice

Description

Video is where ordinary web-app habits break down. Files are gigabytes rather than kilobytes, processing a single upload takes minutes to hours, and delivering it to millions of viewers adds up to terabits a second. "Design YouTube" or "design Netflix" is a favourite interview question because each of those three facts needs its own answer.

In this lesson:

  1. Why the simple version fails, and the numbers that decide the design.
  2. Uploading huge files reliably, in resumable parts.
  3. The transcoding pipeline: chunks, workers and a bitrate ladder.
  4. Adaptive bitrate streaming (HLS and DASH).
  5. Delivery through a CDN, metadata, and storage tiers.

The first version, and why it breaks

A startup adds video to its app the simple way. POST /upload sends the file to an app server, which runs ffmpeg to make an MP4 and saves it. GET /video/42 streams that MP4 back. It works perfectly in the demo.

Then a creator uploads a two-hour 4K recording over hotel Wi-Fi. The upload dies at 80% and has to start again from zero. When it finally arrives, the conversion ties up a request thread for forty minutes. And viewers on phones keep stalling, because the only version that exists is one big 20 Mbps file.

Video breaks the habits of a normal web app. Files are gigabytes, processing takes minutes to hours, and delivery is measured in terabits a second. Each of those needs its own answer.

The numbers

  • 1 million uploads a day, averaging 5 minutes long and about 500 MB raw.
  • 200 million viewers a day, with up to 20 million watching at the same time.
  • At about 4 Mbps per viewer, peak delivery is 20 million × 4 Mbps = 80 Tbps.
  • Playback should start within 2 seconds, and adjust to the viewer's connection instead of stalling.

No fleet of app servers sends 80 Tbps. That number alone tells you the video must come from a CDN, a network of caches close to viewers.

Uploading

Don't send gigabytes through your app servers. Instead:

  • The API hands the app pre-signed URLs: temporary permissions to upload straight to the object store (such as Amazon S3).
  • The app uploads in parts (say 64 MB each). Each part can be retried on its own, so a dropped connection resumes from the last finished part instead of starting over. This is called a multipart, resumable upload.
  • When every part is up, the app tells the API, which records the video as PROCESSING.

The transcoding pipeline

Transcoding means converting the video into the formats and sizes viewers need. It's slow and CPU-heavy, so it never runs inside a web request:

Upload finished

Video API: status PROCESSING

Transcode job queue

Splitter: 10-second chunks

Worker

Worker

Worker ...

Object store: segments + manifests

All chunks done: status READY

Upload finished

Video API: status PROCESSING

Transcode job queue

Splitter: 10-second chunks

Worker

Worker

Worker ...

Object store: segments + manifests

All chunks done: status READY

  1. The API puts a transcode job on a queue.
  2. The video is cut into chunks (say 10 seconds), so hundreds of workers can encode different parts at the same time. A two-hour video then takes minutes instead of hours.
  3. Each chunk is encoded at several sizes and qualities, called a bitrate ladder: for example 240p at 0.4 Mbps up to 1080p at 6 Mbps, plus 4K for 4K sources.
  4. The output is cut into segments a few seconds long, with manifests (playlists) that list them, and saved back to the object store.
  5. When every chunk is done, the video is marked READY.

Workers crash and jobs get retried, so every step must be safe to repeat: encoding the same chunk twice must produce the same segment file.

Adaptive bitrate streaming

With HLS or DASH (the two standard formats), the player first downloads a manifest that lists every version of the video and its segments. While playing, it keeps measuring how fast segments arrive and how much video it has buffered, and it picks the version for each next segment:

CDNPlayerCDNPlayerThe train enters a tunnelGET manifestversions 240p ... 1080p, segment listsGET 480p segment 1 (start small, start fast)GET 1080p segment 2 (connection is fast)GET 360p segment 3 (avoid a stall)GET 1080p segment 4 (back to full speed)
CDNPlayerCDNPlayerThe train enters a tunnelGET manifestversions 240p ... 1080p, segment listsGET 480p segment 1 (start small, start fast)GET 1080p segment 2 (connection is fast)GET 360p segment 3 (avoid a stall)GET 1080p segment 4 (back to full speed)

The video gets a bit blurrier for a few seconds instead of freezing. Starting with a low-bitrate first segment also makes playback start quickly.

Delivery

Segments and manifests are ordinary files, so a CDN caches them in locations near viewers, with the object store as the origin it fetches from on a miss.

  • Segments never change after they're written (a re-encode gets new paths), so they can be cached for a very long time.
  • Manifests for live streams change constantly, so they get short cache times.
  • Popular videos end up served almost entirely from the CDN, and the origin barely notices them.

Metadata and storage tiers

Titles, owners, processing status and the list of renditions live in a metadata database, with a cache in front for popular videos. The video bytes live in the object store.

Storage is the other big bill. Keep the versions people watch in standard storage. Move the raw originals, which you keep only in case you need to re-encode, to a cheaper cold storage tier.

Which piece solves what

ProblemPiece
Huge uploads over unreliable networksMultipart, resumable uploads straight to object storage
Slow, CPU-heavy conversionA job queue and many workers encoding chunks in parallel
Viewers on different connectionsA bitrate ladder, plus HLS or DASH adaptive streaming
80 Tbps of deliveryA CDN in front of the object store
Storage costWatched versions in standard storage, originals in cold storage

Common mistakes

  • Uploading through app servers. Gigabytes tie up your servers and fail on bad networks.
  • Transcoding inside the request. A forty-minute HTTP request is an outage waiting to happen.
  • One version of the video. Phones on slow networks stall, and everyone else downloads more than they need.
  • Serving video from your own servers. Terabits a second need a CDN.
  • Non-repeatable workers. A retried job that produces different files breaks caching and wastes storage.

Check yourself

Try to answer before opening each one - recalling beats re-reading.

1. Why split a video into chunks before transcoding?

Show answer

So many workers can encode different parts at the same time, and a long video finishes in minutes instead of hours. A failed chunk is also retried on its own instead of restarting the whole video.

2. What does the player do when the connection slows down halfway through a video?

Show answer

It picks a lower-bitrate version, listed in the manifest, for the next segments. Playback continues at lower quality instead of stalling, and it switches back up when the connection recovers.

3. Why can a CDN cache segments for a very long time?

Show answer

A segment never changes once it's written. A new encode gets a new path, so a cached copy can never go stale.

Key takeaways

  • Upload in resumable parts, straight to object storage, with pre-signed URLs.
  • Transcode in the background: a queue, chunks, many workers, a bitrate ladder, then mark the video ready.
  • Store HLS or DASH segments plus manifests. The player picks the bitrate for each segment.
  • Serve through a CDN with the object store as origin. Terabits don't come from app servers.
  • Metadata in a database with a cache; video bytes in object storage; originals in cold storage.

Quick revise

The whole skill on one page, for the night before an interview.

Everything from the lesson and the deep dive on one page. Skim it before a design interview, and open the full lesson for anything that doesn't ring a bell.

The numbers

QuantityEstimateSo...
Uploads1 M/day, ~5 min, ~500 MB raw eachResumable uploads straight to object storage
Concurrent viewersUp to 20 M
Peak delivery20 M × 4 Mbps = 80 TbpsOnly a CDN can serve this
PlaybackStarts in < 2 s, adapts instead of stallingAdaptive bitrate streaming

Which piece solves what

ProblemPiece
Huge uploads over bad networksMultipart, resumable uploads (e.g. 64 MB parts) via pre-signed URLs
Slow, CPU-heavy conversionJob queue → split into ~10 s chunks → many workers in parallel
Viewers on different connectionsA bitrate ladder (240p 0.4 Mbps … 1080p 6 Mbps) + HLS or DASH
Terabits of deliveryCDN in front of the object store (the origin)
Storage costWatched renditions in standard storage; raw originals in cold storage
MetadataDatabase (title, owner, status, renditions) with a cache

Status flow

Upload done → PROCESSING → job queued → chunks encoded at every ladder step → segments + manifests written → READY (or FAILED after the retry limit).

Adaptive streaming

The player downloads a manifest listing every rendition, then picks the bitrate for each next segment from measured throughput and buffer level - start low for a fast start, step down in a tunnel, step back up after. Blurry for a few seconds beats frozen.

The traps

  • Uploading through app servers.
  • Transcoding inside the request.
  • One version of the video - phones stall, everyone downloads too much.
  • Serving video from your own servers.
  • Non-repeatable workers - a retried chunk must produce the identical segment.
  • Long cache times on live manifests (they change every few seconds); short ones on immutable segments.

Staff-level points, one line each

  • A 5-step ladder totals 11.7 Mbps → 5.26 GB per hour of video; 83,333 hours/day → ~439 TB of renditions + 500 TB of raw originals a day, before replication. Per-title encoding (Netflix, 2015) and skipping high rungs for unwatched videos cut it.
  • Encoding at ~10 CPU-minutes per video minute: 50 M CPU-minutes/day ≈ 34,722 cores around the clock; autoscale on queue depth. VP9/AV1 save bandwidth but cost several times more to encode - use them for popular videos.
  • Chunking sets finish time: a 2-hour video = 720 × 10 s chunks; 200 workers at 60 s per chunk → 4 rounds ≈ 4 minutes.
  • CDN hit ratio decides origin load at 80 Tbps: 90% → 8 Tbps, 95% → 4 Tbps, 99% → 0.8 Tbps. Tiered caching (origin shield), pre-positioning (Netflix Open Connect inside ISPs), long segment TTLs; the long tail always misses.
  • Segment length: 2 s → 10 M requests/s for 20 M viewers, 4 s → 5 M, 6 s → 3.3 M. Shorter = faster adaptation and lower live latency, but more requests and worse compression (a keyframe per segment). Apple's HLS guidance: 6 s for on-demand.
  • Bitrate choice: throughput-based (overreacts), buffer-based (Netflix, SIGCOMM 2014), hybrids; avoid frequent switching.
  • Live: always-on encoders, LL-HLS / low-latency DASH (CMAF chunks) for seconds of latency, very short manifest TTLs, edge request coalescing for the newest segment.
  • Protection: signed URLs/tokens at the edge; DRM (Widevine, FairPlay, PlayReady) with one CENC-encrypted segment set; license server checks entitlement.
  • Failures: poison uploads → retry limit, DLQ, FAILED; viral video on a cold CDN → coalescing + shield; premieres → pre-warm CDN and scale license/metadata; automated checks on every rendition (duration, audio, decodability).

Say it in an interview

  • "80 terabits a second only comes from a CDN, so everything is designed as cacheable files."
  • "Uploads go straight to S3 in resumable parts; the API only records metadata."
  • "Transcoding splits the video into chunks so hundreds of workers finish a 2-hour file in minutes."
  • "Going from 95% to 99% CDN hit ratio cuts origin traffic five times - that's where I'd invest."

Practice

This skill comes with 9 multiple-choice questions that tell you which misconception a wrong answer reveals and 1 graded problem. Your answers are graded and your mastery is tracked, so you'll know when the skill holds up. Running code and saving progress need a free account.

Practice Design a Video Streaming Service free

Design a Video Streaming Service

HardProSystem design problem

Design the backend of a video platform: creators upload videos, and viewers watch them on phones, laptops and TVs. Arrows go from the caller to what it calls; mark an arrow async when the caller hands work off.

The full statement, the examples and the hidden test suite are part of AI Proof Engineers Pro.

Practice Design a Video Streaming Service free

No card needed. Lessons, practice questions and easy problems are free forever.

Free plan, no card · 7-day Pro trial · Cancel anytime