StackMonkey
Home / Templates / Video Streaming

Designing an Adaptive Bitrate Video Pipeline

Video streaming represents over 65% of global internet downstream traffic. Learn how to design a fault-tolerant HLS/DASH video delivery network with dynamic chunk encoding, multi-tier CDN caching, and stampede-proof origin shields.

Daily Video Plays
100M views
500M video minutes / day
Peak Outbound Egress
4.8 Tbps
99.8% served from CDN edge
New Upload Ingest
50,000 / day
60 TB raw media daily
Startup Playback Time
< 800 ms
p99 initial frame render
Step 1 of 4

Bandwidth & Transcoding Math

Video architectures are defined by petabyte-scale egress and heavy compute transcoding loads. Here is the mathematical foundation for bandwidth and storage budgeting.

Egress Bandwidth Budget

  • 1. Average Bitrate: Modern adaptive streaming encodes in H.264 / AV1 across 1080p (4.5 Mbps), 720p (2.2 Mbps), 480p (1.0 Mbps), and 360p (600 Kbps). Blended average playback stream: 2.5 Mbps.
  • 2. Concurrent Watchers: 500M video minutes / 1,440 minutes = ~347,000 average concurrent streams. Peak prime-time viewing multiplier (3.5x) = 1.2 million concurrent active streams.
  • 3. Total Egress: 1.2M streams * 2.5 Mbps = 3.0 Tbps peak baseline, scaling to 4.8 Tbps during major live broadcasts. Origin servers can never absorb this directly; CDN edge caching is non-negotiable.

Transcoding Compute & Storage Footprint

  • 1. Ingress Volume: 50,000 video uploads/day with average duration of 6 minutes = 300,000 source minutes daily.
  • 2. Transcoding Factor: Each video generates 5 bitrate ladders segmented into 4-second `.ts` or `.m4s` chunks. Transcoding consumes ~2x real-time CPU minutes = 600,000 compute minutes/day. Requires a fleet of 500 parallel GPU/CPU worker pods.
  • 3. Annual Storage Accumulation: Crunched output totals ~150 MB per video across all resolutions. 50,000 * 150 MB = 7.5 TB/day = 2.74 PB per year stored in object storage.
Step 2 of 4

Adaptive Bitrate Streaming: HLS vs. DASH Chunking

Continuous video playback over variable cellular networks requires dynamic chunk switching. The client video player continuously monitors buffer fullness and TCP throughput to select the optimal bitrate ladder.

Chunk Size: 2s vs. 6s Trade-off

Smaller 2-second chunks reduce startup latency and switch bitrates faster when user bandwidth drops, but increase HTTP request overhead by 300% and reduce video compression efficiency (more I-frames).

Standard practice uses 2-second chunks for the initial 3 segments of a video to ensure instant start (< 800ms), then transitions to 4-second or 6-second chunks for steady-state playback.

Client ABR State Machine

The player does not query the backend for bitrate advice. It uses a purely client-side heuristic algorithm (e.g. BOLA or MPC):

if buffer_fill < 4s: switch to lowest resolution (prevent rebuffering)
if buffer_fill > 15s and throughput > 1.5 * bitrate_1080p: step up ladder
segment_download_time > segment_duration: step down immediately
Step 3 of 4

Origin Egress Saturation & Thundering Herd Stampede

When a new episode drops or a live stream starts, millions of users simultaneously request the exact same manifest file and chunk 001. See how cache misses bring down storage origins.

The Origin Stampede Collapse

Suppose 500,000 viewers join a live broadcast at 8:00 PM sharp. The edge CDN has zero cached copies of chunk segment_0001.ts (file size 1.2 MB).

Without request collapsing, 500,000 edge nodes forward the miss to the origin shield: 500,000 * 1.2 MB = 600 GB requested within a 2-second window = 2.4 Tbps origin ingress spike.

The S3 / storage origin rate limits connections with 503 SlowDown errors. The CDN marks the backend dead, cascading 504 Gateway Timeout errors to 100% of the player fleet.

Production Shielding Architecture
  • Request Collapsing (Wait-on-Lock): Edge CDN locks incoming requests for the same chunk URI. Only one request is forwarded to the origin; all remaining requests block and receive the cached response.
  • Two-Tier Origin Shield: Place a dedicated intermediate caching layer (e.g. Fastly Shield / Cloudflare Tiered Cache) between regional edge PoPs and the S3 storage bucket.
  • Pre-warming Viral Manifests: Push newly published video manifests and initial 3 video chunks proactively to Tier-1 regional POPs before releasing the video link to consumers.
Step 4 of 4

Six-Component Media Streaming Grid

The complete infrastructure powering global low-latency playback from edge PoPs down to distributed object storage.

01 路 Global Anycast Edge CDN
Cloudflare / Fastly CDN PoPs
Terminates TLS via Anycast routing, caches video segments with byte-range support, and serves 99.8% of media requests within 20ms of the viewer.
02 路 Manifest Ingress & Auth
Edge Worker Playback Gateways
Generates signed, dynamic `.m3u8` / `.mpd` playlists based on client DRM licensing, geographic CDN routing, and client bitrate capabilities.
03 路 Origin Shield Caching Tier
Varnish / NGINX Origin Shields
Consolidates cache misses across all regional edge PoPs. Implements request collapsing to guarantee only one outbound fetch hits S3 per viral chunk.
04 路 Distributed Transcode Pipeline
FFmpeg + Kubernetes GPU Workers
Pulls raw master uploads from S3, splits video into parallel chunks, encodes 5 bitrate resolutions simultaneously, and writes packaged HLS playlists back to storage.
05 路 Master Media Object Storage
Amazon S3 / Google Cloud Storage
Immutable, 99.999999999% durable blob storage holding raw source masters and chunked video artifacts organized by `video_id/resolution/chunk_xxx.ts`.
06 路 Video Metadata & State Store
ScyllaDB / DynamoDB
Stores video titles, view counts, user resume timestamps, and bitrate profiles. Supports sub-10ms key-value lookups during manifest generation.
Interactive Discrete Event Simulation

Simulate the Video Streaming Network Live

Model multi-tier CDN hit ratios, trigger origin cache stampedes, and verify buffer playback continuity under variable simulated consumer network latency.