Markdown Editor

Video Streaming System Design Template (Reference Design)

Video upload and ABR streaming: chunked transcoding, renditions ladder, CMAF HLS/DASH, CDN, DRM note, view counts, storage tiers

Як використовувати: Use when hosting video on demand. Fill uploads, views and watch time first; egress usually dominates cost. The main pitfall is a generic renditions ladder and no storage tiering, which inflates CDN and storage bills.

Перегляд

System Design: [Video platform name]

Reference design for video upload and adaptive bitrate streaming: resumable upload, a transcoding pipeline that produces a renditions ladder, CMAF packaging for HLS and DASH, CDN delivery, a DRM note, view counting, storage tiers and cost. It follows the structure of the System Design Document template and is pre-filled with a worked design to adapt. Values marked Example are assumptions: replace them and recompute; egress and storage numbers move by orders of magnitude with your audience.

Document control

FieldValue
Document ID[SDD-VID-001]
System / feature[Video upload and streaming]
Version[0.1]
Status[Draft / In review / Approved / Implemented / Superseded]
Author(s)[@author]
Reviewers[@reviewer-1], [@reviewer-2]
Last updatedYYYY-MM-DD
Related[PRD], [CDN contract], [Content licensing requirements], [ADR: codec strategy]

Approvals

RoleNameDecisionDate
Tech lead[@name][Approved / Changes requested]YYYY-MM-DD
Staff / principal engineer[@name][Decision]YYYY-MM-DD
SRE / operations[@name][Decision]YYYY-MM-DD
Media / video engineering lead[@name][Decision]YYYY-MM-DD
Finance (CDN and storage cost)[@name][Decision]YYYY-MM-DD

Revision history

VersionDateAuthorChange summary
0.1YYYY-MM-DD[@name]First draft for design review
0.2YYYY-MM-DD[@name]Example: CMAF packaging to serve HLS and DASH from one set of segments
0.3YYYY-MM-DD[@name]Example: AV1 renditions only for videos above 1 000 views
1.0YYYY-MM-DD[@name]Example: Approved

Contents

1. Overview

1.1 Problem statement

[Example: Creators upload MP4 files that we serve as progressive downloads from a single bucket. Mobile viewers on weak networks stall every 20 seconds, a 4 GB upload fails if the connection drops, and our cloud egress bill grew 4x in a year.]

1.2 Proposed solution

[Example: Clients upload directly to object storage with resumable, chunked uploads. An upload event starts a transcoding workflow that splits the source into chunks, encodes them in parallel into a ladder of renditions, and packages fragmented MP4 segments (CMAF) with HLS and DASH manifests. Players choose the rendition per segment based on measured throughput (adaptive bitrate). A CDN serves segments from the edge with an origin shield in front of storage. View events stream into an aggregation pipeline for counts and analytics. Older and rarely watched renditions move to cheaper storage tiers.]

1.3 Decisions requested from reviewers

IDQuestionRecommended optionSection
Q-01Example: Codecs at launch?H.264 for all; AV1 added for popular videos7.2, 10
Q-02Example: Segment duration?4 s segments, 2 s GOP7.3
Q-03Example: DRM in v1?Only for licensed catalogue; user uploads use signed URLs7.5
Q-04Example: Keep source files?Yes, in archive tier after 30 days7.7
[Q-nn][Question][Option][Section]

2. Requirements

2.1 Functional requirements

IDRequirementPriority
FR-01Example: Upload files up to 20 GB and 4 h, resumable after network lossMust
FR-02Example: Transcode to an adaptive ladder from 240p to 1080p (4K for eligible creators)Must
FR-03Example: Play on web, iOS, Android and TV apps with adaptive bitrateMust
FR-04Example: Thumbnails and preview spritesMust
FR-05Example: Captions (WebVTT) uploaded or generatedShould
FR-06Example: View counts visible within 5 minutesShould
FR-07Example: DRM for licensed contentMust for licensed catalogue
[FR-nn][Requirement][Must / Should / Could]

2.2 Non-functional requirements

IDQualityTargetMeasured as
NFR-01Startup timeExample: Video start p90 at or below 1.5 sPlayer telemetry
NFR-02RebufferingExample: Rebuffer ratio below 0.5% of watch timePlayer telemetry
NFR-03Processing timeExample: 10-minute 1080p video playable within 5 min of uploadWorkflow metrics
NFR-04AvailabilityExample: 99.95% playback availabilitySynthetic playback probes per region
NFR-05DurabilityExample: Sources and renditions 11 nines (object storage class)Provider SLA, checksums
[NFR-nn][Quality][Target][Measurement]

2.3 Out of scope

  • [Example: live streaming (separate design: ingest, low-latency packaging)]
  • [Example: recommendations and search]
  • [Example: in-browser video editing]
  • [Item deferred, with the release that will take it]

3. Capacity estimation

3.1 Assumptions

InputSymbolValueSource
Uploads per dayUUExample: 100 000Growth plan
Average durationddExample: 10 minCurrent uploads
Average source bitratebsb_sExample: 8 Mbit/sCurrent uploads
Ladder bitrate sum (H.264)blb_lExample: 10.7 Mbit/s7.2
Views per dayVVExample: 100 millionAnalytics forecast
Average watch time per viewwwExample: 5 minAnalytics
Average delivered bitratebdb_dExample: 3 Mbit/sPlayer telemetry
Encoding costeeExample: 6 vCPU-min per minute of video (full ladder)Benchmark
Peak to average factorkkExample: 2 (evening)Traffic history

3.2 Storage

Source per video: 600 s×8 Mbit/s=4 800 Mbit=600 MB600 \ \text{s} \times 8 \ \text{Mbit/s} = 4\,800 \ \text{Mbit} = 600 \ \text{MB}. Renditions per video: 600×10.7=6 420 Mbit≈800 MB600 \times 10.7 = 6\,420 \ \text{Mbit} \approx 800 \ \text{MB}.

Sday=U×(600+800) MB=105×1.4 GB=140 TB/dayS_{day} = U \times (600 + 800) \ \text{MB} = 10^{5} \times 1.4 \ \text{GB} = 140 \ \text{TB/day}
Syear≈140 TB×365≈51 PB/yearS_{year} \approx 140 \ \text{TB} \times 365 \approx 51 \ \text{PB/year}

Storage tiering (7.7) is therefore part of the design, not an afterthought.

3.3 Transcoding compute

C=U×d×e=105×10×6=6×106 vCPU-min/day=105 vCPU-hours/dayC = U \times d \times e = 10^{5} \times 10 \times 6 = 6 \times 10^{6} \ \text{vCPU-min/day} = 10^{5} \ \text{vCPU-hours/day}
average concurrency=10524≈4 200 vCPU,peak≈8 400 vCPU\text{average concurrency} = \frac{10^{5}}{24} \approx 4\,200 \ \text{vCPU}, \qquad \text{peak} \approx 8\,400 \ \text{vCPU}

Spot or preemptible capacity suits this load because chunks are short and retryable.

3.4 Egress

Eday=V×w×bd=108×300 s×3 Mbit/s=9×1010 Mbit=11.25 PB/dayE_{day} = V \times w \times b_d = 10^{8} \times 300 \ \text{s} \times 3 \ \text{Mbit/s} = 9 \times 10^{10} \ \text{Mbit} = 11.25 \ \text{PB/day}
Bˉ=9×1010 Mbit86 400 s≈1.04 Tbit/s,Bpeak≈2.1 Tbit/s\bar{B} = \frac{9 \times 10^{10} \ \text{Mbit}}{86\,400 \ \text{s}} \approx 1.04 \ \text{Tbit/s}, \qquad B_{peak} \approx 2.1 \ \text{Tbit/s}

3.5 Summary

QuantityEstimateDesign consequence
New storage~140 TB/day, ~51 PB/yearTiering, source archive, delete unused renditions
Transcoding~4 200 vCPU average, ~8 400 peakChunked parallel encoding on spot capacity
Egress~11 PB/day, ~2 Tbit/s peakMulti-CDN with origin shield; cache hit ratio is the key cost lever
View events~1 160/s average (plus heartbeats)Stream aggregation, not database counters

4. API design

4.1 Endpoints

MethodPathPurposeAuthIdempotent
POST/v1/videosCreate video record, get resumable upload sessionCreator tokenWith Idempotency-Key
PUTupload session URL (object storage)Upload chunks with byte rangesSigned sessionYes per chunk
POST/v1/videos/{id}/completeFinish upload, start processingCreator tokenYes
GET/v1/videos/{id}Metadata and processing stateToken or publicYes
GET/v1/videos/{id}/playbackManifest URLs, signed CDN token, DRM licence URLViewer token or publicYes
POST/v1/viewsView start and heartbeat eventsViewer sessionDedup by viewId + sequence

4.2 Request and response examples

The playback endpoint returns short-lived signed URLs for both manifest types:

GET /v1/videos/v_9QK2/playback HTTP/1.1
Authorization: Bearer [viewer token]
{"videoId": "v_9QK2", "hls": "https://cdn.example.net/v/v_9QK2/master.m3u8?token=eyJ...", "dash": "https://cdn.example.net/v/v_9QK2/manifest.mpd?token=eyJ...", "expiresAt": "2026-03-14T20:00:00Z", "drm": null, "captions": [{"lang": "en", "url": "https://cdn.example.net/v/v_9QK2/en.vtt"}]}

4.3 Errors and limits

StatusProblem typeWhen
403geo-restrictedViewer region not licensed
409not-readyProcessing not finished
413upload-too-largeSource over limit
422unsupported-mediaSource cannot be decoded
429upload-quota-exceededCreator daily upload quota reached

5. Data model

5.1 Entities

Video metadata lives in a database; media objects live in object storage and are referenced by key.

5.2 Storage choices

DataStoreKeyMain queriesWhy
Video metadataRelational database (sharded by video_id)video_idGet by ID; list by ownerTransactions on state changes
SourcesObject storage, standard then archive tiersrc/{video_id}Read for re-encodeLarge, rarely read after processing
Segments and manifestsObject storage, standard then infrequent-access tierv/{video_id}/{rendition}/{n}.m4sRead by CDN originImmutable, cacheable forever
Workflow stateDurable workflow enginejob_idResume and retry stepsLong-running, failure-prone
View countsStream aggregates into wide-column storevideo_id, dayTotals and daily seriesHigh write rate

6. High-level design

Uploads and playback never pass through application servers; the API only issues signed URLs and tracks state.

ComponentResponsibilityScales by
Video APICreate videos, issue upload sessions and playback tokensStateless replicas
Workflow orchestratorRun processing steps with retries and timeoutsWorkflow workers
Encoder poolEncode chunks per renditionvCPU or GPU instances, spot
CMAF packagerProduce segments, HLS and DASH manifests, encryption when DRM is onStateless workers
CDN and origin shieldServe segments; collapse origin requestsProvider capacity
Stream aggregationDeduplicate and count viewsStream partitions
[Component][Responsibility][Scaling unit]

7. Detailed design

7.1 Upload and processing workflow

Processing state is a small state machine stored on the video record; the workflow engine drives transitions and retries each step independently.

A video becomes ready as soon as the 360p and 720p renditions exist, so viewers can start watching while higher renditions finish.

7.2 Renditions ladder

RenditionResolutionVideo bitrate (H.264)AudioTypical use
Example: 1080p1920x10805 000 kbit/s128 kbit/s AACWi-Fi, TV
720p1280x7203 000 kbit/s128 kbit/sGood mobile, laptop
480p854x4801 500 kbit/s96 kbit/sAverage mobile
360p640x360800 kbit/s96 kbit/sWeak mobile, fast start
240p426x240400 kbit/s64 kbit/sVery weak networks

The video bitrates sum to 10.7 Mbit/s (the blb_l input in 3.1; audio is shared across renditions and adds little). Per-title encoding can lower these bitrates substantially for simple content such as slides or animation; adopt it once quality metrics (for example VMAF) are in place. AV1 renditions save roughly 30% or more bandwidth at equal quality on supporting devices but cost several times more compute, so they are produced only for videos above Example: 1 000 views, where egress savings exceed encoding cost.

7.3 Chunked encoding and packaging

  • The source is probed, then split at keyframes into chunks of about 30 s.
  • Each chunk is encoded per rendition with a fixed GOP of 2 s and closed GOPs so segments align across renditions; players can switch at any segment boundary.
  • The packager writes CMAF fragmented MP4 segments of 4 s, one HLS master playlist with media playlists, and one DASH MPD, all referencing the same segment files.
  • Failed chunks are retried individually (up to 3 attempts, then on on-demand capacity), so a spot interruption costs at most one chunk.

7.4 Playback path (critical path)

The player fetches a manifest, then segments, choosing a rendition per segment from throughput and buffer level.

Manifests for on-demand videos are immutable after ready, except when renditions are added; they are cached for minutes, segments for a year.

7.5 DRM note

For licensed content, segments are encrypted with Common Encryption (CENC) using the cbcs scheme, which lets one set of CMAF segments work with FairPlay (Apple devices), Widevine (Chrome, Android) and PlayReady (Windows, many TVs). The licence service checks entitlement and issues keys with policies (rental expiry, output protection). DRM requires licensing agreements with each DRM vendor, adds a licence round trip to startup and complicates offline playback; user uploads without licensing obligations use signed URLs and token-authenticated CDN access instead.

7.6 View counting and consistency model

  • Players send a view-start event with a random viewId, then heartbeats. A view counts once watch time passes Example: 30 s, which filters autoplay noise.
  • The stream job deduplicates by viewId, drops bot traffic by rules and reputation, and updates per-minute aggregates; public counts are refreshed every 5 minutes. Counts are eventually consistent and can be corrected downward after fraud review.
  • Video metadata and state changes are strongly consistent in the database. Segments are immutable objects, so CDN caches can never serve a mixed version of a segment; deletions propagate by CDN purge within minutes.

7.7 Storage tiers

ObjectDay 0-30Day 31-365After 365 days
SourceStandardArchive tier (hours to restore)Archive tier
Popular renditions (views in last 30 days)StandardStandardStandard
Unpopular renditionsStandardInfrequent accessInfrequent access; delete 1080p if no views for a year and re-encode on demand from source
Thumbnails, manifestsStandardStandardStandard

8. Scalability and performance

ConcernApproachLimit before redesign
EgressMulti-CDN, origin shield, long cache lifetimesCDN commit levels; consider own edge caches above ~10 Tbit/s
Viral videoShield collapses requests; first segments pre-warmed for trending videosEdge capacity per region
Encoding backlogSpot pool autoscaling on queue depth; priority for short videosRegional spot availability
Metadata readsCache playback responses for 60 s[Limit]
Origin requestsTarget CDN hit ratio of 95% or moreShield capacity

Startup budget for a video start (target p90 1.5 s):

StepBudget
Playback API150 ms
Master and media playlists200 ms
First segment at 360p (4 s x 0.9 Mbit/s, about 450 KB)600 ms
Decoder start150 ms
Headroom400 ms

9. Reliability, security and operations

9.1 Failure modes

FailureImpactDetectionMitigation
CDN provider degraded in a regionRebuffering, failed startsPlayer error and rebuffer rates per CDNMulti-CDN switching by player or DNS steering
Spot capacity reclaimedSlower processingWorkflow queue ageChunk retries; fallback to on-demand for jobs older than 15 min
Corrupt renditionPlayback errors at a pointPlayer decode errors by renditionAutomated validation after packaging; re-encode
Metadata DB unavailableNew playback sessions failAPI error rateCached playback responses; read replicas
Upload interruptedCreator frustrationSession abandonment rateResumable sessions valid 7 days
[Failure][Impact][Signal][Mitigation]

9.2 Security and abuse

ThreatControl
Hotlinking and unauthorised redistributionSigned CDN tokens bound to path and expiry; DRM for licensed content
Malicious media files exploiting decodersDecode in sandboxed, unprivileged workers with resource limits; patch media libraries promptly
Illegal or harmful contentUpload scanning against hash lists, classifiers, reporting and takedown workflow
View count fraudDedup by viewId, bot detection, retroactive correction
[Threat][Control]

9.3 Observability

SignalMetric or logAlert threshold
Startup timePlayer p90Above 1.5 s for 15 min in a region
Rebuffer ratioRebuffer time / watch timeAbove 0.5%
Playback errorsFatal errors per 1 000 startsAbove 2
Processing timeUpload complete to ready p95Above 5 min for 10-min videos
CDN hit ratioEdge hits / requestsBelow 95%

9.4 Cost estimate

ItemUnit costQuantityMonthly cost
CDN egressExample: $0.005/GB at committed volumeExample: ~337 PBExample: ~$1.7 million
Object storage (standard, IA, archive)[$/TB-month per tier]Example: +4.2 PB/month[$]
Transcoding compute (spot)[$/vCPU-hour]Example: 3 million vCPU-hours[$]
DRM licences[$/licence or flat][n][$]
Total[$]

10. Trade-offs and alternatives

DecisionOptionsChosenWhyWhat we give up
DeliveryProgressive MP4; HLS only; DASH only; CMAF for bothCMAF for HLS and DASHOne set of segments for all devicesOlder devices without fMP4 support need a TS fallback or are unsupported
CodecsH.264 only; H.264 + HEVC; H.264 + AV1H.264 + AV1 for popular videosUniversal compatibility plus bandwidth savings where it paysTwo encoder pipelines
EncodingWhole file per worker; chunked parallelChunked parallelFast turnaround, cheap retries on spotChunk boundary handling and stitching complexity
Transcoding serviceManaged cloud service; own pipeline[Own / Managed][Reason: cost at scale, control of ladder][Cost]
CDNSingle CDN; multi-CDNMulti-CDNResilience and price leverageSteering logic and per-CDN tokens
Storage of unpopular renditionsKeep all; delete and re-encode on demandDelete 1080p after a year without viewsLarge storage savingsFirst viewer waits or gets 720p
[Decision][Options][Chosen][Why][Cost]

11. Delivery plan and risks

11.1 Milestones

MilestoneScopeExit criterionTarget date
M1Resumable upload, H.264 ladder, HLS via one CDNRebuffer ratio below 1% in betaYYYY-MM-DD
M2CMAF HLS + DASH, origin shield, view countingCDN hit ratio 95%; counts within 5 minYYYY-MM-DD
M3Multi-CDN and storage tieringEgress cost per GB down 20%YYYY-MM-DD
M4DRM for licensed catalogue; AV1 for popular videosLicence partner certificationYYYY-MM-DD

11.2 Rollout and rollback

[Example: Re-encode the existing catalogue in the background, most viewed first. The player chooses adaptive streaming when a ready ladder exists and falls back to the old MP4 otherwise; rollback sets a flag that forces the MP4 path.]

11.3 Risks

IDRiskLikelihoodImpactMitigationOwner
R-01Example: Egress cost exceeds forecastMediumHighPer-title encoding, AV1, committed-use CDN contracts[@name]
R-02Example: Spot shortage delays processingMediumMediumOn-demand fallback; multiple instance types and regions[@name]
R-03Example: DRM integration delays licensed launchMediumHighStart certification early; use a packaging vendor[@name]
[R-nn][Risk][L / M / H][L / M / H][Mitigation][@name]

12. Appendices

12.1 Open questions

IDQuestionOwnerDue
OQ-01Example: Do we offer 4K for all creators or only partners?[@name]YYYY-MM-DD
OQ-02Example: Automatic captions: in-house model or vendor?[@name]YYYY-MM-DD
[OQ-nn][Question][@name]YYYY-MM-DD

12.2 Glossary

TermMeaning
ABRAdaptive bitrate: player switches renditions based on network conditions
RenditionOne encoded version of a video at a resolution and bitrate
LadderSet of renditions offered for a video
CMAFCommon Media Application Format: fragmented MP4 segments shared by HLS and DASH
GOPGroup of pictures: frames between keyframes
Origin shieldCache layer between CDN edges and storage that reduces origin load
[Term][Meaning]

12.3 References

ReferenceUse
RFC 8216 HTTP Live StreamingHLS playlists
ISO/IEC 23009-1 (MPEG-DASH)DASH manifests
ISO/IEC 23000-19 (CMAF)Segment format
ISO/IEC 23001-7 (Common Encryption)DRM encryption schemes
W3C WebVTTCaptions

Standard and licence note

Based on common industry practice for video-on-demand platforms and on the specifications cited in 12.3; no text from ISO/IEC standards is reproduced. This is a reference design to adapt, with illustrative numbers and prices. Original text written for this collection. Template licence: MIT.

Схожі шаблони