Design: video streaming platform

In one sentence

Upload the original once in resumable parts, transcode it in parallel chunks into a bitrate ladder of short segments, and serve them from a CDN; the player picks a quality per segment.

Bytes flow one way through the pipeline; viewers fetch small static segments from the CDN and switch quality between them.

How it works

  • Upload in resumable parts to object storage via pre-signed URLs; an event starts processing.
  • Transcode keyframe-aligned chunks in parallel into a bitrate ladder, packaged as ~6 s HLS/DASH segments.
  • The player picks a rung per segment from throughput and buffer level: that is adaptive bitrate.
  • Segments are immutable static files, so a CDN serves nearly every byte; egress (~1 Tbps here) is the bill.
  • Tier storage: hot renditions near viewers, originals in a cold tier, fewer rungs for rarely watched videos.

Check yourself

Answer to mark it learned; your answers aren't scored.

A new video goes viral. Overall CDN hit rate stays above 95%, yet your object-storage origin is throttling requests and some viewers stall in the first minutes. Best fix?

Go deeper

Do this round in 45 minutes System design round
Full explanation

Requirements

Functional: upload, process and watch videos on any device; resume where you left off. Non-functional: playback starts fast and rarely rebuffers, uploads survive flaky networks, and egress cost stays under control. Assume 500k uploads/day and 100M views/day, ~5 minutes each.

Questions I'd ask: on-demand only, or live too? Which devices and codecs? Global audience? DRM?

High-level design

Upload: the client gets pre-signed URLs and sends the file in parts (S3 multipart: up to 10,000 parts), so a dropped connection resumes. The original lands in object storage and an event starts processing.

Transcode: split at keyframes, transcode chunks in parallel into each rung of a bitrate ladder (Apple's example: 145 kbps at 234p up to 7.8 Mbps at 1080p), then package ~6 s segments for HLS (RFC 8216) and DASH, plus thumbnails and captions. Each task is idempotent; a failed chunk retries alone.

Serve: a metadata DB holds titles, renditions and state; the playback API returns a manifest URL; segments are immutable files served by a CDN.

The hard parts

Adaptive bitrate. The manifest lists the variants; the player fetches one segment at a time and switches rung at segment boundaries using measured throughput and buffer level. Netflix's buffer-based ABR cut rebuffers 10–20% versus its then-default algorithm (SIGCOMM 2014).

Egress cost. 100M views × 5 min × ~3 Mbps (assumed average) ≈ 11 PB/day, ~1 Tbps on average. CDN hit rate and bits per view (codec, per-title ladders) are the levers; Netflix even places its own Open Connect caches inside ISPs.

Code HLS manifests: the ladder and one rendition
textHLS manifests: the ladder and one rendition
#EXTM3U
# master.m3u8: one variant per rung; BANDWIDTH = peak bits/s incl. audio
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-STREAM-INF:BANDWIDTH=400000,RESOLUTION=640x360
360p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2200000,RESOLUTION=960x540
540p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=4900000,RESOLUTION=1280x720
720p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=8600000,RESOLUTION=1920x1080
1080p/index.m3u8

#EXTM3U
# 720p/index.m3u8: one rendition, ~6 s fMP4 segments
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:6
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="init.mp4"
#EXTINF:6.006,
seg_00001.m4s
#EXTINF:6.006,
seg_00002.m4s
#EXT-X-ENDLIST
Real example

A creator uploads a 10-minute 4K file (~3 GB, assumed) on hotel Wi-Fi. The app sends 100 MB parts; part 17 fails and only that part is retried. Processing splits the video into ~60 chunks of 10 s and transcodes them in parallel, so it takes about as long as the slowest chunk, not the whole film. A viewer on a train starts at 360p for a fast start, climbs to 1080p as the buffer fills, and drops to 540p in a tunnel without stalling.

Trade-offs +3 · −3

+ You gain

  • Segments are plain HTTP files: any CDN caches them, with no streaming servers to scale.
  • Chunked parallel transcoding makes processing time track chunk length, not video length.
  • ABR keeps playback going on bad networks by trading quality for continuity.

− You pay

  • Storage multiplies: every rung and format is another copy of the video.
  • Segment length adds delay: live viewers trail the edge by several segments.
  • Egress dominates cost; CDN hit rate and contracts decide the bill.

Use it when

On-demand video for a large audience on variable networks: user uploads, courses, film and TV catalogs, product video.

Avoid it when

Two-way real-time video (calls, cloud gaming): segment-based delivery adds seconds, so use WebRTC. A small catalog: buy a managed video service.

Numbers to know 5
  • Egress: assume 100M views/day × 5 min × ~3 Mbps → ~11 PB/day, ~1 Tbps average.
  • Apple's example H.264 ladder: 145 kbps (416×234) to 7,800 kbps (1080p); 9 rungs sum ~25.6 Mbps.
  • Apple HLS spec: ~6 s target segment duration, a keyframe every 2 s.
  • S3 multipart (Nov 2026): up to 10,000 parts of 5 MiB–5 GiB; objects up to 48.8 TiB.
  • Buffer-based ABR cut Netflix rebuffers 10–20% vs its default algorithm (SIGCOMM 2014).
Common pitfalls 4
  • Transcoding a whole file on one machine: a 2-hour film blocks a worker for hours. Split at keyframes.
  • Keyframes not aligned across rungs: the player can't switch cleanly at segment boundaries.
  • Starting playback at the top rung: slow first frame and an early rebuffer. Start low, then climb.
  • No origin shield: a viral video's first misses from every edge stampede the origin.
Interview questions 3

Answer out loud first, then reveal.

A video goes viral. What breaks first, and how do you protect it?Show answer

Not the CDN for hot segments: after the first requests they're cached at every edge. The risk is the miss storm, hundreds of edge locations fetching the same new segments from origin at once. I add an origin shield so each segment leaves storage once, and coalesce concurrent misses. Metadata reads get a short-TTL cache, and view counts go through a stream aggregator instead of one row update per view.

How would you cut the egress bill?Show answer

First, fewer bits per view: newer codecs like HEVC or AV1 for devices that support them, and per-title ladders so simple content needs less bitrate for the same quality. Second, a higher hit rate: origin shield and long TTLs, since segments are immutable. Third, cheaper delivery: committed CDN volume or, at Netflix scale, caches inside ISPs like Open Connect. I'd track cost per hour watched.

What changes for live streaming?Show answer

The pipeline becomes real time: ingest the feed, transcode it into the ladder with fixed keyframe intervals, and publish segments as they finish, so the playlist grows without an end tag. Latency becomes the trade-off: players stay three target durations behind the edge, ~18 s with 6 s segments. Low-latency HLS, with partial segments, cuts that to a few seconds. Transcoders need hot standbys, because a crash is visible to everyone.

Deep dive 3

Upload and transcoding pipeline

Clients upload straight to object storage with pre-signed multipart URLs, never through your API servers; AWS suggests multipart from ~100 MB, with parts of 5 MiB–5 GiB. Completion emits an event that starts a DAG: validate → split at keyframes → transcode each (chunk, rung) → package segments and manifests → thumbnails and captions → publish. Key each task by (video, rung, chunk) so retries overwrite instead of duplicating. Per-title ladders (Netflix's approach) give simple content like animation fewer bits for the same quality. Mark the video ready only when every required rung exists.

Segments and adaptive bitrate

Apple's HLS spec recommends ~6 s segments and a keyframe every 2 s, with keyframes aligned across rungs so the player can switch at any segment boundary. Shorter segments switch faster but add requests and per-segment overhead. Throughput-based ABR picks the rung the measured bandwidth can sustain; buffer-based ABR picks from buffer occupancy and avoids reacting to noisy estimates. Start low for a fast first frame, then climb. Live is harder: clients stay at least three target durations behind the live edge (RFC 8216), ~18 s with 6 s segments, unless you use low-latency HLS.

CDN, storage tiers and cost

Segments never change, so cache them with long TTLs. Put an origin shield between edges and storage, so a new viral video's segments leave storage once instead of once per edge location. Netflix's Open Connect gives qualifying ISPs cache appliances at no charge, serving popular titles from inside their networks. Storage multiplies with every rung and format: Apple's 9-rung example ladder sums ~25.6 Mbps, ~190 MB per minute of video. Keep originals in a cold tier, re-transcode on demand, and give rarely watched videos fewer rungs.