Build a Large-Scale Live Video Broadcasting Service
System DesignModel answerLast updated
Design a platform where creators broadcast live video to millions of viewers with low delay, adaptive quality, real-time chat, stream discovery, and replay after the stream ends.
Problem
Design a platform on which creators can go live and large audiences can watch them within a few seconds. You have about 45 minutes. Treat the discussion as a design review: clarify scope, size the system, sketch the architecture, then go deep on the hardest parts.
What the platform must do
- A creator starts a broadcast and pushes video to the platform in real time.
- Viewers watch with near-live delay. Glass-to-glass latency must stay under 10 seconds.
- Each stream has a live chat that feels instant (sub-second delivery for most users).
- Viewers can browse and find streams that are currently live.
- Finished broadcasts are recorded and can be replayed on demand.
- Playback adapts to the viewer's network, so people on weak connections can still watch.
Quality targets
- A single popular stream may have millions of concurrent viewers.
- Broadcasts must not drop mid-stream; the system should be highly available.
- Every tier should scale horizontally as audience grows.
Assumed scale
- 50M daily active users, 10M concurrent viewers at peak, 100K concurrent broadcasters at peak.
- Average broadcast lasts 2 hours; the average stream has about 100 viewers, but the top streams have millions.
- Typical bitrates: 1080p about 6 Mbps, 720p about 3 Mbps, 480p about 1.5 Mbps, 360p about 0.8 Mbps.
- VOD retention of 30 days.
Out of scope
Payments and subscriptions (mention only), ML-based moderation, mobile client details, and authentication internals.
What to cover
- Clarifying questions and a back-of-the-envelope estimate (ingest, egress, storage, request rates).
- A high-level architecture with the main components and APIs.
- A deep dive into the video path (ingest, transcoding, packaging, delivery through CDNs).
- How chat scales to a very large stream.
- How recording/VOD and viewer counts/discovery work.
- The key trade-offs and failure scenarios.
Hints
Hint 1
Split the system into three independent paths: video ingest, video delivery, and chat. Ask what happens to each if the others fail.
Hint 2
Compute egress (10M viewers at about 3 Mbps is roughly 30 Tbps) and playlist request rate. Then check the latency budget: classic 6-second HLS segments with a three-segment player buffer cannot meet a 10-second target, so what must change?
Hint 3
For the hottest stream, count chat deliveries per second (viewers times messages per second). Naive fan-out is impossible, so think about gateway-level subscriptions, batching, sampling, and rate limiting.
Hint 4
Think about the thundering herd when a new segment appears: how do edge and mid-tier caches collapse requests so the origin sees hundreds, not millions?
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
Live streaming is a write-once, read-millions problem under a hard latency budget. I would organize the design around three independent paths so that a failure in one does not take down the others:
- Ingest path: one writer per stream, encoded and packaged.
- Delivery path: massive read fan-out through CDNs.
- Chat path: a separate real-time messaging system.
A chat outage must never interrupt playback.
Estimates and what they imply
| Quantity | Calculation | Implication |
|---|---|---|
| Ingest | 100K x 6 Mbps = 600 Gbps | Regional ingest clusters, not one data center |
| Egress | 10M x 3 Mbps = 30 Tbps | Multi-CDN is mandatory |
| Playlist requests | 10M viewers / 2 s refresh = about 5M req/s | Cache manifests at the edge with very short TTLs |
| Recording | 100K x 2 h x 6 Mbps = about 540 TB/day raw, about 1 PB/day with renditions | Object storage with lifecycle tiers; about 30 PB at 30 days |
| Chat on a hot stream | 1M viewers x 1K msg/s = 1B deliveries/s | Needs batching and sampling; naive fan-out is impossible |
Latency budget
Classic HLS (6 s segments, player buffers about 3) yields 20-30 s of delay, which violates the target. Use 2 s segments with aligned 2 s keyframes, or Low-Latency HLS with 200-500 ms partial segments. Approximate budget: ingest 0.5 s, transcode and package 1 s, CDN 0.5 s, player buffer 2-4 s, for a total of about 5-6 s.
APIs
POST /v1/streams -> {stream_id, stream_key, ingest_url}
RTMP rtmp://ingest.../live/{stream_key}
GET /v1/streams?category=&cursor= -> live streams, paginated
GET /v1/streams/{id} -> metadata + playback URL (master playlist)
WS /v1/chat/{stream_id} -> receive batched messages
POST /v1/chat/{stream_id}/messages
GET /v1/vods/{vod_id}
Video bytes never pass through API servers; playback is plain HTTP GET against the CDN.
Data model
- Stream (sharded SQL): id, broadcaster, title, category, status, ingest node, start/end times.
- Live index (Redis sorted sets per category, scored by viewer count) for browsing; Elasticsearch for title/tag search.
- Segments in object storage at
/{stream}/{rendition}/{seq}.ts; playlists are small mutable objects rewritten every segment. - Chat messages (Cassandra): partition
(stream_id, time_bucket), clustered by time-ordered message id. Write-heavy, append-only. - VOD metadata: id, stream id, duration, manifest URL, storage tier.
Architecture
Broadcaster -RTMP/SRT-> regional Ingest -> Transcoder -> Packager (HLS/LL-HLS)
-> Origin storage -> Shield cache -> Multi-CDN edges -> Viewers
\-> VOD pipeline (async, via queue)
Chat: Clients <-> stateless WS gateways <- pub/sub per stream <- Chat API
Lifecycle events (Kafka) -> metadata / discovery service
Deep dives
Ingest and transcoding
- The broadcaster connects to the nearest ingest node, which validates the stream key and pins the stream to a transcoder.
- Produce an ABR ladder (1080p/720p/480p/360p) with keyframes aligned across renditions so the player can switch at segment boundaries.
- Cost lever: most streams have few viewers. Pass through the source plus one low rendition, and enable the full ladder only after viewership crosses a threshold. This cuts transcoding compute severalfold.
- Failure handling: if an ingest node dies, the encoder reconnects via DNS/anycast and resumes the same stream id; the packager inserts a discontinuity tag. For top streams, run redundant transcoders in two zones and fail over at the playlist level.
Delivery
- Segments are immutable: long TTL. Playlists change each segment: TTL of about one segment duration.
- Thundering herd: when segment N+1 appears, millions request it at once. Use request collapsing at edge and shield tiers so the origin sees roughly one request per PoP and per region, hundreds in total.
- Multi-CDN steering picks a CDN per viewer using cost, regional performance, health, and client QoE beacons. It gives redundancy and negotiating leverage.
- The player picks a rendition per segment from measured throughput and buffer level.
Chat at scale
- Clients hold WebSockets to stateless gateways. Each gateway subscribes to a stream's pub/sub channel only if it has local viewers of that stream, so fan-out becomes publisher to hundreds of gateways to local sockets.
- Batch deliveries every 200-500 ms to cut frames and syscalls dramatically.
- Tier by audience: small streams deliver everything; huge streams apply slow mode, rate limits, and per-viewer sampling, since nobody can read 1,000 messages per second. Always deliver broadcaster, moderator, and the user's own messages.
- Persist asynchronously to Cassandra for replay and moderation. Chat favors availability; an occasional dropped message is acceptable.
Viewer counts and discovery
- Never increment a DB row per view. Edges and gateways send heartbeats; an aggregator computes approximate counts every 10-30 s and updates the Redis sorted sets. Eventual consistency is fine.
VOD
- A stream-ended event goes on a queue. Workers stitch segments, optionally re-encode with a slower, more efficient codec (HEVC/AV1), generate thumbnails, and write the VOD manifest.
- Lifecycle policies move assets hot, then infrequent-access, then archive, and delete after 30 days. At about 30 PB, tiering is the main cost control.
Trade-offs
- Latency vs. stability: shorter and partial segments reduce delay but raise request rate and rebuffering risk. Sub-second use cases (auctions, co-streaming) need WebRTC-style delivery instead, at much higher cost per viewer.
- Quality vs. cost: a full ladder for every stream is wasteful; transcode on demand by audience size.
- Consistency vs. availability: chat, counts, and discovery are eventually consistent; stream metadata and stream-key ownership need stronger guarantees.
- Single CDN vs. multi-CDN: multi adds steering complexity but protects against regional outages.
Common mistakes
- Sending video through application servers instead of a CDN.
- Using default 6 s segments and missing the latency target.
- Ignoring the chat fan-out arithmetic (1B deliveries/s).
- Updating viewer counts synchronously in a database.
- Transcoding every stream at every quality regardless of audience.
- Coupling chat and video so one failure takes down both.