A long film is cut into short clips, each prepared in several qualities. Your player downloads clip after clip from a shop near you, picking a lower quality clip when your internet slows down, so the film keeps playing instead of freezing.
Design a video platform like YouTube: creators upload videos, the platform processes them into streamable formats, and viewers around the world watch with quick start times and smooth playback on any device and network. The core challenges are the processing pipeline and delivering enormous bandwidth cheaply.
Uploads: 500K/day x 300 MB avg = 150 TB/day of raw video
+ transcoded renditions (all together roughly the size of the original)
-> ~100+ PB/year before replication: object storage, lifecycle tiers
Views: 1B/day ~ 12K video starts/s on average
Watching: 1B x 5 min = 5B min/day / 1,440 min ~ 3.5M concurrent viewers (avg)
Egress: 3.5M x ~3 Mbps ~ 10 Tbps average, several times that at peak
-> only possible with a CDN (and caches inside ISPs)
POST /v1/videos { title, description, size } -> { video_id, upload_urls[] (pre-signed, multipart) }
POST /v1/videos/{id}/complete -> 202 (start processing)
GET /v1/videos/{id} -> { title, status, manifest_url: "https://cdn.../v/{id}/master.m3u8", views }
POST /v1/videos/{id}/views -> 204 (batched client beacons)
UPLOAD + PROCESSING
creator -> API (metadata DB: status=UPLOADING) -> pre-signed multipart URLs
creator == bytes ==> object storage (raw bucket)
object created event -> [ queue ] -> processing DAG:
split into chunks (e.g. 4-10 s at keyframes)
-> parallel transcode each chunk x each rendition (240p ... 4K, H.264/VP9/AV1)
-> package into HLS/DASH segments + manifests
-> thumbnails, content checks (copyright, safety)
-> processed bucket; metadata status=READY
PLAYBACK
viewer -> API: video page + manifest URL
player -> CDN: master manifest -> picks rendition by bandwidth
-> segments seg_001.ts, seg_002.ts ... (cache hits at the edge)
CDN miss -> origin shield -> processed bucket
master.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360
360p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720
720p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080
1080p/index.m3u8
720p/index.m3u8 -> list of ~4-6 s segments
The player measures download speed and buffer level every segment and
switches renditions between segments: no stall, just a quality change.
Because everything is plain HTTP files, any CDN can cache it; the "server" is just static files.
videos(video_id PK, owner_id, title, description, status, duration, created_at)
renditions(video_id, rendition, codec, bitrate, manifest_key, PRIMARY KEY(video_id, rendition))
views: client beacons -> stream -> aggregated per minute -> counter store
(approximate, eventually consistent; exact dedupe of bots done offline)