Video streaming
Creators upload video. Viewers stream it worldwide at a quality matched to their connection. Bandwidth, not compute, is the dominant cost.
EnvelopeUploads to global playback · adaptive bitrate · 90% of bytes from edge
What the design must do
- Upload accepted and durable before processing
- Transcode to multiple bitrates asynchronously
- Segmented delivery with adaptive bitrate
- Overwhelming majority of bytes served from the edge
The worked envelope
Assumed. 100k uploads/day averaging 10 minutes at ~500 MB source, 10M views/day averaging 10 minutes at 3 Mbps, five renditions per title.
| Upload ingest | 100k × 500 MB = 50 TB/day |
| Transcode work | 100k × 10 min × 5 renditions = 5M min/day ≈ 3,500 cores at 1× realtime |
| Stored output | source + ~700 MB of renditions ≈ 120 TB/day = 44 PB/yr |
| Playback egress | 10M × 600 s × 3 Mbps ÷ 8 = 2.25 PB/day |
| Sustained rate | 2.25 PB ÷ 86,400 s ≈ 26 GB/s, peak ~78 GB/s |
| Origin load | at 90% edge hit rate → 225 TB/day |
What the numbers decide. Playback egress is forty-five times the upload volume. This is not a storage system that happens to serve video; it is a bandwidth system that happens to store some.
Two consequences follow immediately and neither is negotiable. Bytes cannot pass through your application tier in either direction — uploads go straight to object storage by presigned URL, playback comes from the edge — because 26 GB/s through your own servers is an absurd fleet to run. And 3,500 cores of transcoding is a batch workload with a queue and a cost per title, which is why transcoding is asynchronous and why the video is not playable the instant the upload finishes.
The decisions, and what each one costs
Client uploads directly to object storage via a presigned URL
- Because
- 50 TB/day never touching the app tier removes the fleet you would otherwise size for upload bandwidth, and a 10-minute mobile upload no longer holds a server thread
- The cost
- You never see the bytes, so validation moves after the fact — a worker checks the object and only then marks it usable
- Rejected
- Proxying uploads through the API, which pays for 50 TB/day of ingress twice and times out on slow connections
Asynchronous transcode into an adaptive bitrate ladder
- Because
- 3,500 cores of work cannot be synchronous, and viewers arrive on connections from fibre to a train tunnel — one rendition serves neither well
- The cost
- Publish is delayed by minutes; storage is roughly 2.4× the source; a failed rendition needs retry without redoing the rest
- Rejected
- Transcoding on demand at playback, which pays the CPU cost on every view instead of once per title
CDN serves playback; origin is a fallback
- Because
- 26 GB/s sustained is CDN-scale, and video segments are immutable so they cache perfectly — a 90% hit rate turns 2.25 PB/day into 225 TB
- The cost
- A CDN bill that dominates the budget, and purge latency when something must be taken down
- Rejected
- Serving from origin with a cache in front, which is the same idea without the geography that makes it work
Lifecycle old titles to archive storage
- Because
- 44 PB/yr accumulating at hot-tier prices is the line item that eventually exceeds all others, and view counts decay sharply with age
- The cost
- A cold title takes minutes to first byte, so the product must handle "restoring" as a visible state
- Rejected
- Keeping everything hot, which prices the long tail at the same rate as this week’s releases
Components in the reference design
- Client
- Browser or mobile app
- CDN
- Edge cache for static and cacheable content
- Load Balancer
- L7 routing, TLS termination, health checks
- App Service
- Stateless business logic
- Object Store
- S3-style blobs, media, backups
- Queue
- Work distribution, one consumer per message
- Worker
- Async consumer, background jobs
- SQL DB
- Relational, ACID, joins
The reference design
Upload. The client uploads directly to object storage using a pre-signed URL. The video bytes never pass through your application servers — routing gigabytes through your API tier wastes bandwidth and destroys your latency. The app service only issues the URL and records metadata.
Transcoding. One source file becomes many renditions: 240p through 4K, each split into 2–10 second segments, plus a manifest listing them. This is expensive, embarrassingly parallel, and completely asynchronous — the upload returns immediately, a queue fans the work to a worker fleet, and the video becomes playable rendition by rendition.
Split long videos into chunks and transcode chunks in parallel, or a two-hour film blocks one worker for an hour.
Adaptive bitrate. The player measures its own throughput and picks the next segment's quality accordingly. The intelligence lives in the client; the server just serves whichever segment was requested. That is why segmentation matters — quality can change every few seconds without interrupting playback.
Delivery is the whole cost. Segments are static files with content-hashed names, so they cache at the edge indefinitely. Target 90%+ CDN offload; every percentage point of origin traffic is a real bandwidth bill. Popular titles are pre-warmed into edge PoPs before a release rather than pulled on first request.
Metadata versus media. Titles, view counts and comments are small structured data in a relational store. Media is blobs. Keeping them separate is what lets each scale on its own axis — and it is why "which database" is the wrong first question for this system.