Design a Globally Scalable Video-on-Demand Platform
System DesignModel answerLast updated
Architect an architecture for video ingestion, parallel adaptive-bitrate transcoding, and low-latency global delivery serving millions of concurrent streams.
Architect an end-to-end Video-on-Demand (VOD) platform capable of ingesting raw high-definition video from content partners and delivering low-latency playback to millions of concurrent viewers globally across diverse device types and network conditions.
System Requirements
Functional Requirements
- Content Ingestion & Processing: Content partners must be able to upload raw master video files (mezzanines). The platform must automatically transcode, package, and publish these videos.
- Catalog & Discovery: Viewers can browse and search the media catalog, view video details, and retrieve playback sessions.
- Adaptive Playback: Viewers must experience smooth video playback that dynamically adapts to changing client bandwidth and device capabilities without manual re-buffering.
Non-Functional Requirements
- Massive Scale & Throughput: Support up to 10 million concurrent active playback sessions during peak hours.
- Low Playback Latency: Achieve a Time-To-First-Frame (TTFF) of under 2 seconds at p90 globally.
- High Availability: Target 99.99% uptime for the playback control plane and content delivery paths.
- Resource Efficiency: Optimize storage footprint and bandwidth spending without compromising perceived video quality.
Scope of Discussion
- System scale estimation and bandwidth math.
- End-to-end architectural separation between write/ingest and read/playback paths.
- Asynchronous video transcoding and packaging pipeline design.
- Multi-tier CDN delivery and caching strategies.
- Data models for catalog management, video manifests, and user watch progress.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Scale Estimation & Constraints
Workload Characteristics
- Read/Write Asymmetry: Ingestion is heavy on CPU and storage writes but low in request volume (~500 titles/day). Playback is heavily read-dominant, bandwidth-bound, and strictly latency-sensitive.
- Active User Base: 200 million registered accounts, 10 million peak concurrent streaming sessions.
- Delivery Bitrate: Average streaming bitrate across resolutions is ~5 Mbps per client.
- Peak Egress Bandwidth: $10,000,000 \text{ streams} \times 5 \text{ Mbps} = 50 \text{ Tbps}$.
- Implication: No centralized origin storage can sustain 50 Tbps directly. Edge delivery via Content Delivery Networks (CDNs) and ISP-embedded caches is mandatory.
Storage Math
- Catalog Size: 50,000 titles $\times$ 1.5 hours average duration = 75,000 hours of content.
- Adaptive Bitrate (ABR) Encoding Ladder:
- Encoded across 6 target renditions (ranging from 360p @ 400 kbps to 4K @ 16 Mbps).
- Cumulative ladder bitrate $\approx 20 \text{ Mbps}$ total per codec family.
- Storage required per content hour per codec $\approx 20 \text{ Mbps} \times 3600 \text{ s} / 8 = 9 \text{ GB/hour}$.
- Codec Matrix: Supporting both legacy devices (H.264/AVC) and modern devices (HEVC / AV1):
- Encoded Storage: $75,000 \text{ hours} \times 9 \text{ GB/hour/codec} \times 2 \text{ codecs} \approx 1.35 \text{ PB}$.
- Original Mezzanine Files (ProRes/DNxHR master files at ~150 GB/hour): $75,000 \times 150 \text{ GB} = 11.25 \text{ PB}$.
2. API Design
The control plane remains lightweight and decoupled from actual media bytes. Media segments flow strictly between object storage, CDNs, and client video engines.
Ingestion API (Partner Operations)
POST /v1/ingest/jobs
Content-Type: application/json
{
"title": "Cosmic Adventures Ep 1",
"content_type": "EPISODE",
"file_size_bytes": 161061273600,
"checksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
Response 201 Created:
{
"job_id": "job_998124",
"upload_urls": [
"https://storage.provider.com/raw-bucket/job_998124/part1?signature=...",
"https://storage.provider.com/raw-bucket/job_998124/part2?signature=..."
]
}
POST /v1/ingest/jobs/job_998124/complete
Response 202 Accepted:
{
"job_id": "job_998124",
"status": "PROCESSING"
}
Playback API (Client Operations)
POST /v1/playback/session
Authorization: Bearer <user_jwt>
Content-Type: application/json
{
"title_id": "ttl_48921",
"device_profile": {
"supported_codecs": ["HEVC", "H264"],
"supported_containers": ["CMAF"],
"max_resolution": "2160p",
"hdr_support": ["HDR10"]
}
}
Response 200 OK:
{
"session_id": "sess_88291034",
"manifest_url": "https://cdn.platform.com/manifests/ttl_48921/master.m3u8?token=exp=1690000000~hmac=a9b4...",
"resume_position_seconds": 412.5,
"license_server_url": "https://drm.platform.com/license/v1"
}
POST /v1/telemetry/heartbeat
Authorization: Bearer <user_jwt>
{
"session_id": "sess_88291034",
"current_position_seconds": 442.5,
"current_rendition_bitrate": 4500000,
"buffer_health_seconds": 18.2,
"rebuffer_events_count": 0
}
3. High-Level Architecture
+-----------------------------------+
| Content Partner / Mezzanine |
+-----------------------------------+
|
v Direct Multipart Upload
+-----------------------------------+
| Raw Storage (S3 / GCS Bucket) |
+-----------------------------------+
|
| Bucket Event Trigger
v
+-----------------------------------------------------------------------------------+
| INGGESTION & PROCESSING PIPELINE |
| |
| +------------------+ +-------------------+ +--------------------------+ |
| | Event Queue | --> | Pipeline | --> | Parallel Transcode | |
| | (Kafka / SQS) | | Orchestrator | | Workers (Spot Instances) | |
| +------------------+ +-------------------+ +--------------------------+ |
| | |
| v |
| +------------------+ +-------------------+ +--------------------------+ |
| | Catalog DB Update| <-- | DRM Encryptor & | <-- | CMAF Chunk Stitcher | |
| | & Cache Invalidate| | Package Generator | | & QC Automated Checker | |
| +------------------+ +-------------------+ +--------------------------+ |
+-----------------------------------------------------------------------------------+
|
v Output fMP4 Chunks + Manifests
+-----------------------------------+
| Encoded Origin (Object Storage) |
+-----------------------------------+
|
v Read Miss
+-----------------------------------+
| Regional Shield Cache Tier |
+-----------------------------------+
|
v Cached Segment Delivery
+-----------------------------------+
| Edge CDNs (Akamai, Fastly, Open) |
+-----------------------------------+
^
| HLS/DASH Requests over HTTP/3
+-----------------------------------+
| Client Player Application |
+-----------------------------------+
4. Ingestion & Transcoding Pipeline Deep Dive
Transcoding a 2-hour 4K master file as a monolithic task takes hours and risks complete failure if worker nodes crash.
Parallel Segmented Transcoding Pipeline
- Splitting at Keyframes: The raw mezzanine file is analyzed for scene cuts or forced intra-frame intervals (Group of Pictures - GOP) and sliced into independent $2 \text{ to } 4 \text{ second}$ chunks.
- Dynamic Worker Allocation: An orchestration engine (e.g., Temporal workflow DAG) enqueues chunk transcoding tasks to auto-scaling worker clusters using preemptible/spot cloud compute instances.
- For a 2-hour movie split into 2-minute processing batches, 60 worker nodes run concurrently, compressing processing duration down to $< 5 \text{ minutes}$.
- Idempotency & Retries: Tasks are uniquely identified by
hash(mezzanine_id, time_offset, target_profile). If a worker dies, another node retries without corrupting state. - CMAF Packaging & Storage Optimizations:
- Instead of storing separate TS chunks for Apple HLS and MP4 chunks for MPEG-DASH, we encode using CMAF (Common Media Application Format) using fragmented MP4 (
.m4s) containers. - A single set of media segments serves both HLS and DASH manifests, instantly saving ~50% in storage cost and doubling CDN edge cache efficiency.
- Instead of storing separate TS chunks for Apple HLS and MP4 chunks for MPEG-DASH, we encode using CMAF (Common Media Application Format) using fragmented MP4 (
+-----------------------------------+
| Unified CMAF Media Segments |
| (fragmented MP4) |
+-----------------------------------+
/ \
/ \
v v
+----------------------------+ +----------------------------+
| HLS Manifest (.m3u8) | | DASH Manifest (.mpd) |
| Points to .m4s segments | | Points to .m4s segments |
+----------------------------+ +----------------------------+
- Quality Assessment: Before marking a title active, automated checks execute VMAF (Video Multi-Method Assessment Fusion) score calculations against the raw source to verify picture quality remains above a set floor (e.g., VMAF > 93).
5. Global Delivery & Playback Performance Strategy
To achieve low latency (Time-To-First-Frame $< 2 \text{ s}$) and eliminate rebuffering, media delivery relies on a multi-tiered distribution architecture.
Multi-Tiered Cache Topology
- ISP Embedded Appliances (Tier 1): Cache hardware installed directly inside partner internet service provider datacenters (e.g., Netflix Open Connect model). Popular titles reside within 1 hop of the end-user.
- Edge CDNs (Tier 2): Commercial third-party CDNs handle geo-distributed edge traffic.
- Regional Shield Caches (Tier 3): Positioned between Edge PoPs and Origin Object Storage.
- Request Collapsing: If 10,000 edge nodes request segment
video_720p_0041.m4ssimultaneously during a launch event, the Shield Cache collapses those down to a single read request to the origin storage.
- Request Collapsing: If 10,000 edge nodes request segment
Client Requests ---> Edge PoPs (Miss) ---> Regional Shield Cache ---> Origin Storage
|
(Collapses 10,000 requests into 1)
Manifest & Invalidation Handling
- Media files (
.m4s) are immutable. Once generated, their path contains an explicit content hash (e.g.,/media/ttl_99/v1/720p/seg_0012.m4s). - Cache control headers for media segments set long TTLs:
Cache-Control: public, max-age=31536000, immutable. - Takedowns or content rights changes do not purge edge caches. Instead, authorization tokens inside short-lived signed URLs are revoked at the Playback API gateway layer.
Client-Side Adaptive Bitrate (ABR) Logic
- Playback engines run hybrid throughput- and buffer-based algorithms (such as BOLA or Dynamic ABR).
- Fast Startup Protocol:
- Initial video segment request fetches a low-bitrate chunk (e.g., 480p) to fill the initial frame buffer instantly.
- As soon as the buffer crosses 4 seconds, the player steps up the ABR ladder based on bandwidth measurements.
6. Data Modeling
Storage Engine Selection
- Metadata & Catalog Service: Relational Database (PostgreSQL) with aggressive Redis read caching. Data is highly structured, write volumes are low, and transaction consistency is necessary for release schedules and regional rights.
- Watch State & Resume Progress: Wide-Column NoSQL Store (Cassandra / DynamoDB). Requires sub-millisecond writes capable of absorbing 10M concurrent client heartbeat bursts every 30 seconds.
Data Schemas
PostgreSQL Schema (Catalog Control Plane)
CREATE TABLE titles (
title_id VARCHAR(64) PRIMARY KEY,
type VARCHAR(16) NOT NULL, -- MOVIE, EPISODE
name VARCHAR(255) NOT NULL,
release_date TIMESTAMP WITH TIME ZONE,
maturity_rating VARCHAR(16),
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE media_renditions (
rendition_id VARCHAR(64) PRIMARY KEY,
title_id VARCHAR(64) REFERENCES titles(title_id),
codec VARCHAR(16) NOT NULL, -- H264, HEVC, AV1
resolution_height INT NOT NULL, -- 480, 720, 1080, 2160
bitrate_bps INT NOT NULL,
manifest_relative_path VARCHAR(512) NOT NULL,
CONSTRAINT unique_rendition UNIQUE(title_id, codec, resolution_height)
);
DynamoDB Schema (User Telemetry & State)
Table: user_playback_state
- Partition Key (
PK):USER#<user_id> - Sort Key (
SK):TITLE#<title_id>
| Attribute Name | Type | Example |
|---|---|---|
user_id | String | "usr_991823" |
title_id | String | "ttl_48921" |
last_position_seconds | Number | 442.5 |
duration_seconds | Number | 7200.0 |
completed_flag | Boolean | false |
updated_at | Number (TTL) | 1690000442 |
7. Operational Trade-Offs & Key Decisions
1. Per-Title / Per-Shot Encoding vs. Fixed Bitrate Ladders
- Fixed Ladder: Uses pre-defined bitrates for specific resolutions (e.g., 1080p always encoded at 4.5 Mbps). Simple, but wastes bandwidth on simple animated content and starves high-motion sports content.
- Per-Shot VMAF-Targeted Encoding: Analyzes frame complexity. A cartoon 1080p stream might achieve optimal VMAF quality at 1.5 Mbps, saving >60% bandwidth, while action scenes get allocated up to 7 Mbps.
- Trade-off: Significantly higher up-front transcode compute costs in exchange for lower ongoing network egress costs.
2. Immediate Consistency vs. High Availability on User Progress State
- Watch history updates use Eventual Consistency with last-write-wins semantics via Cassandra/DynamoDB.
- Trade-off: If a user pauses a video on their phone and immediately presses play on their TV within 1 second, their position might be 5 seconds behind. This micro-inconsistency is acceptable in exchange for preserving system availability during traffic spikes.
3. DRM Licensing vs. Time-To-First-Frame
- Fetching digital rights management (DRM) keys synchronously before video initialization adds round-trips to the playback startup sequence.
- Mitigation: Secure license initialization parameters inside the primary
/playback/sessionpayload and pre-fetch license tokens while the client engine is downloading the initial manifest and segment headers.