Course contents

17. Real-World System Design Lesson 10 of 20

Video Streaming Platform

Design video streaming: resumable uploads, a transcoding queue and its backlog, adaptive bitrate segments, CDN delivery, popularity skew and an origin shield.

25 minAdvanced10 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • Video is write-once, read-millions: processing is a batch pipeline, delivery is a caching problem.
  • Uploads enqueue transcoding tasks per rendition and chunk; workers scale on backlog.
  • Players fetch short segments over HTTP and switch renditions segment by segment.
  • Skewed popularity lets a small edge cache absorb most requests; the long tail reaches the origin.
  • An origin shield merges misses from all edges and coalesces concurrent ones.
  • Egress dominates cost; every cache tier is how you pay for it.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

A video streaming platform accepts uploads, converts them into formats every device can play, and delivers them to viewers worldwide with fast start and no stalls. YouTube, Netflix and Twitch differ in catalogue and live vs on-demand, but share the shape: an ingest and processing pipeline on one side, a multi-tier content delivery network on the other.

Why it exists

Raw uploads come in arbitrary formats and bitrates; viewers have phones on 4G, laptops on Wi-Fi and TVs on fibre. Serving the same file to all of them either stalls the weak connections or wastes the strong ones. And the bandwidth needed for millions of viewers is so large that no single data centre can serve it. The platform exists to encode once into many renditions and to serve them from caches near viewers.

How it works

Requirements. Functional: upload, process, publish, play on any device, seek, adapt quality. Non-functional: playback starts within a couple of seconds and rarely rebuffers; uploads never get lost; published videos are durable; time-to-publish of minutes; cost per hour watched kept low.

Estimates (illustrative). 100 000 uploads a day of 10 minutes each is about 17 000 hours of video a day. With five renditions at an average of 2 Mbit/s, one hour stores roughly 4.5 GB, so storage grows by tens of terabytes a day plus the raw files. Delivery dwarfs everything: 1 million concurrent viewers at 5 Mbit/s is 5 Tbit/s.

Upload. Clients upload in chunks with a resumable protocol (for example tus, or object storage multipart uploads with presigned URLs). Raw files are kept so videos can be re-encoded later with better codecs.

Transcoding pipeline. The video is split into chunks (a few seconds each, cut at keyframes). For each chunk and each rendition a task goes onto a queue; workers transcode tasks in parallel and write segments to storage; a final step writes the manifests. Tasks are idempotent and retryable, so workers can run on interruptible capacity and scale on queue depth or the age of the oldest task.

Adaptive bitrate. Each rendition is a sequence of 2–6 second segments listed in a manifest (HLS .m3u8 or DASH .mpd; CMAF lets both share the same segment files). The player picks a rendition per segment from measured throughput and buffer level. Everything is plain HTTP, so standard CDNs cache it.

CDN delivery. Edges near viewers cache segments. Popularity is heavily skewed (roughly Zipf-like): a small fraction of videos gets most views, so a cache much smaller than the catalogue achieves a high hit ratio. The less skewed the distribution, the more requests fall into the long tail and miss.

Origin shield. Between the edges and the origin sits a shared cache tier. All edges send misses there, so a segment fetched for one region is a hit for the others, and concurrent misses for the same segment collapse into one origin read. The origin then sees only the shield's misses.

When to use it

Any product that serves recorded or live video at scale: on-demand libraries, user-generated video, e-learning, live streaming (with a low-latency variant of the same segment-based design).

When not to

  • A handful of videos with modest traffic: a managed video service or object storage plus a CDN with a single rendition is enough.
  • Real-time two-way video (calls, conferencing): segment-based HTTP delivery adds seconds of latency; use WebRTC with media servers.
  • Very short clips where start time matters more than adaptation: progressive download of a single small file may be simpler.

Trade-offs

Choice You gain You pay
More renditions per video Smoother adaptation on every network Storage and encoding for every video, most of which are rarely watched
Encode the tail on demand Lower storage and compute First viewers wait or get fewer qualities
Newer codecs (HEVC, AV1) Lower bitrate for the same quality, less egress Much higher encoding cost, device support varies
Shorter segments Faster adaptation, lower live latency More requests and manifest updates, lower compression efficiency
Origin shield Origin load cut sharply, fewer duplicate fetches Extra hop on misses, another tier to operate

Alternatives

  • Managed video platforms that handle upload, encoding, packaging and delivery.
  • Progressive download of a single MP4: simple, no adaptation.
  • WebRTC for sub-second interactive streams.
  • ISP-embedded caches: the largest platforms place their own cache appliances inside ISP networks; it only pays off at enormous scale.

Failure modes

  • Transcoding backlog: uploads keep succeeding while time-to-publish grows; alert on the oldest task's age.
  • Poison video: a corrupt upload crashes workers repeatedly; cap retries and dead-letter it.
  • Cold or lost cache tier: misses jump to the next tier; without a shield they hit the origin directly.
  • Viral video / premiere: thousands of concurrent requests for segments not yet cached; coalescing and pre-warming (pushing segments to edges before the start) prevent a stampede.
  • Bad ABR heuristics: oscillating quality or rebuffering; measured on the client.

In production

Measure what viewers feel: start-up time, rebuffering ratio, average bitrate, playback failures, from client telemetry. On the server side watch CDN hit ratio per tier, origin egress, queue age and transcoding cost per hour of video. Use per-title or per-scene encoding to choose bitrates by content complexity. Sign URLs or use tokens for paid content and add DRM where licences require it. Keep raw uploads in cheaper storage classes and move cold renditions there too.

Common misconceptions

  • "Streaming means a long-lived connection pushing video." Modern streaming is the player pulling small HTTP files.
  • "A bigger cache always fixes a low hit ratio." Popularity skew sets the ceiling; the long tail still misses.
  • "Transcoding is done once per video." It is done per rendition and chunk, often again later for new codecs.
  • "The queue makes transcoding faster." It makes uploads independent of transcoding; capacity still sets throughput.

Interview angle

Split the design into upload/processing and delivery early. Interviewers probe: how a large upload survives network failures, how transcoding is parallelised and scaled, what ABR is and why segments are small, how much egress the system needs (do the arithmetic), why a CDN works for video (popularity skew) and what happens with long-tail content, and how the origin is protected (shield, coalescing, pre-warming). Mentioning the storage-versus-compute trade-off for rarely watched renditions stands out.

Model assumptions

The simulation is a simplified model, not a benchmark. Each transcoding request is one task (one rendition of one chunk); the upload API stores the raw chunk (about 30 ms) and enqueues the task. Each transcoder has 4 slots and needs about 1.5 s per task (lognormal, cv 0.3), about 2.7 tasks per second. Viewers request segments of 5 000 videos with Zipf popularity (exponent 1.1, then 0.7 for the long tail). Every edge cache is an LRU of 400 videos that keeps whatever its next hop answers (the origin, later the shield), so its hit ratio emerges from the popularity skew. The shield cache is an LRU of 2 500 videos that sees only the edges' real misses, and the shield coalesces concurrent misses. A failed cache returns misses while down and comes back empty when it recovers. The origin is modelled as a database with 20 connections and about 50 ms per read, about 400 reads per second. The resumable upload and ABR segment fetching are scripted illustrations; the engine does not model bitrates or player buffers. Numbers show behaviour and orders of magnitude only.

The lesson as textEvery step of the simulation, written out.
  1. 1. Few uploads, enormous egress

    Creators upload videos; viewers watch them on every kind of device and network, starting within a couple of seconds and without stalls. Illustrative estimate: 100 000 uploads a day of 10 minutes each is about 17 000 hours of video a day to process, a heavy but steady compute job. Watching is the giant: 1 million concurrent viewers at 5 Mbit/s is 5 Tbit/s of egress, far beyond what any origin data centre should serve directly.

    Uploads use a resumable protocol: the file goes up in chunks, each acknowledged, so a dropped connection resumes instead of restarting. Raw chunks land in object storage. This step is a scripted illustration.

    Scene: A creator uploads a video in chunks; the upload API stores each chunk in raw object storage and acknowledges it. Scripted illustration.

    Key idea: Video is write-once, read-millions: processing is a batch pipeline, delivery is a caching problem.

  2. 2. A queue of transcoding tasks

    Every upload must be transcoded into several renditions (for example 1080p, 720p, 480p, 360p) and cut into short segments. That takes far longer than the upload request, so the upload API stores the raw chunk, puts tasks on a queue (one per rendition and chunk) and answers immediately.

    Three transcoders take tasks off the queue. Here about 6 tasks per second arrive and the three can finish about 8, so they are about two thirds busy and the queue stays short. Chunks of one video transcode in parallel on different machines, which is what keeps time-to-publish low for long videos. This step is simulated.

    Scene: The upload API stores each raw chunk and enqueues transcoding tasks, about 6 per second. Three transcoders process them at about two thirds of their capacity; the queue stays short.

    Key idea: Split each video into independent tasks (rendition × chunk) on a queue: parallel, retryable, and decoupled from the upload.

  3. 3. An upload surge builds a backlog

    One second in, a big event makes everyone upload at once: tasks arrive at 14 per second, while the transcoders still finish about 8. Watch the queue: the backlog grows steadily, by roughly six tasks every second.

    Uploads themselves stay fast and nothing fails: the queue absorbs the surge. The cost is time-to-publish: each new video waits behind everything queued before it. The metric to alert on is the age of the oldest task, not CPU.

    Scene: Tasks arrive at 14 per second, faster than the transcoders can process them. The queue backlog grows steadily while uploads keep succeeding quickly.

    Key idea: A queue converts overload into delay. Uploads keep succeeding; publishing gets later and later until capacity catches up.

  4. 4. Scale transcoders on queue depth

    An autoscaler watches the queue depth and adds three more transcoders. Six can finish about 16 tasks per second, above the 14 arriving, so the queue stays short and time-to-publish is back to minutes of real time instead of hours.

    Transcoding suits cheap, interruptible capacity (spot or preemptible machines): a task that dies with its machine is simply delivered again after its visibility timeout. Hardware encoders (GPUs or dedicated chips) cut cost per task further for the most popular renditions.

    Scene: Six transcoders now process the 14 tasks per second; the queue stays short and every transcoder is busy but not saturated.

    Key idea: Scale workers on backlog (depth or oldest-task age), and use interruptible capacity because tasks are retryable.

  5. 5. Adaptive bitrate: the player picks each segment

    Transcoded renditions are stored as short segments (2–6 seconds) plus a manifest listing them (HLS or MPEG-DASH, usually with CMAF segments shared by both). The player first fetches the manifest, then requests segments one after another, choosing a rendition for each based on measured throughput and how full its buffer is.

    Watch the player: two 1080p segments (large, slow to arrive), then the network weakens and it drops to 360p (small, quick), then climbs back to 720p. No new connection, no restart: just a different URL for the next segment. Because segments are plain files on HTTP, any CDN can cache them. Scripted illustration.

    Scene: The player fetches the manifest from the edge, then segments one by one: two large 1080p segments, a small 360p segment while the network is weak, and a 720p segment as it recovers. Scripted illustration.

    Key idea: Video is delivered as small, cacheable HTTP files; the client adapts quality segment by segment.

  6. 6. Popular videos are served from the edge

    Viewers now request 300 segments per second at the EU edge, spread over 5 000 videos. Popularity is very skewed: a few hits get a large share of views. The edge cache holds segments of 400 videos and keeps the most recently used.

    Most requests are served from the edge, and the origin only sees the misses, a fraction of the traffic. This is why video platforms can serve terabits: the hits are cached close to viewers, near-identical for millions of people. This step is simulated.

    Scene: EU viewers request 300 segments per second through the edge. Most are served from the edge cache; the origin receives only the misses.

    Key idea: Skewed popularity is what makes video cacheable: a small cache holds the head of the distribution and absorbs most of the traffic.

  7. 7. The long tail misses the cache

    Same traffic, same cache, but now viewers spread their attention more evenly: fewer views go to the hits and more to the long tail of videos that each get a few views (think a catalogue full of niche content, or a new region with different tastes).

    The hit ratio falls sharply (from roughly 70% to under 30% here) and the origin receives almost three times as many reads. Its utilisation rises and so does latency for every miss. Popularity skew, not cache size alone, decides how much a CDN can absorb: the tail must be fetched from somewhere.

    Scene: With a flatter popularity distribution the edge cache hit ratio falls from about 70% to under 30% and the origin receives almost three times as many reads.

    Key idea: A flatter popularity curve means a lower hit ratio for the same cache; the long tail lands on the origin.

  8. 8. Add regions, and an origin shield in front

    The platform grows to three regions, each with its own edge serving 200 segments per second. Without anything else, each edge would fetch its misses from the origin separately: the same tail segment requested in three regions means three origin reads.

    An origin shield sits between the edges and the origin: a larger, shared cache layer that every edge asks on a miss. A segment fetched for Europe is then a hit for America and Asia. The shield also coalesces concurrent misses for the same segment into one origin read. Each edge still hits only about 30% (the long tail), and keeps a copy of whatever the shield sends back. The shield sees nothing but those misses, yet hits on more than half of them, because the same tail segments are watched in all three regions. In this run the origin receives less than half of the edges’ misses; without the shield, those misses alone would exceed the roughly 400 reads per second the origin can do.

    Scene: Three regional edges, each with 200 segments per second, send their misses to an origin shield with a shared cache. Only the shield’s misses reach the origin, less than half of the edges’ combined misses.

    Key idea: An origin shield turns N regional misses into one origin read: a shared second cache tier plus request coalescing.

  9. 9. A regional cache fails; the shield absorbs it

    One second in, the EU edge cache fails for two seconds: every EU request becomes a miss and goes to the shield. Without a shield, all of that would land on the origin at once.

    With the shield, most of those requests are hits in the shared cache, because the same segments are popular in other regions too. The origin’s load rises only a little, nothing fails, and EU viewers see slightly higher latency until their cache returns. It comes back empty and refills, mostly from the shield, so the edge is hitting again within a second or two. Layered caches turn a regional failure into a small blip.

    Scene: The EU edge cache fails for two seconds. All EU requests go to the origin shield, which serves most of them from its shared cache; origin load rises only slightly and no request fails. The EU cache comes back empty and refills from the shield.

    Key idea: Each cache tier protects the one behind it: losing an edge cache shifts load to the shield, not straight to the origin.

  10. 10. The design and its trade-offs

    The finished design: resumable uploads into raw storage; a queue of transcoding tasks per rendition and chunk, scaled on backlog; renditions stored as segments and manifests; adaptive bitrate players; regional CDN edges; an origin shield with coalescing in front of the renditions origin.

    Trade-offs to discuss: how many renditions to store (every extra one costs storage for every video, while encoding on demand costs latency and compute; many platforms encode popular videos in more formats and codecs than the tail), newer codecs (AV1 saves bandwidth but costs much more encoding time), segment length (shorter segments adapt faster and cut live latency but mean more requests), and building your own CDN appliances inside ISPs, which only pays off at the very largest scale.

    Scene: The complete platform: upload API, raw storage, transcode queue and six transcoders, renditions origin, origin shield with its cache, and three regional edges with their caches serving viewers.

    Key idea: Transcode once in parallel, store segments, cache them in layers: video cost is dominated by egress, and caching is how you pay for it.