Media & streaming · Advanced
Twitch-style live streaming
RTMP ingest at the edge, routed origin transcoding, two-second HLS segments from a CDN.
Every part, and why it is there
Streamer (OBS)
Encodes their screen and camera at one high quality and pushes it continuously with a stream key. If their upload drops, every viewer sees it.
Ingest PoP
The streamer connects to the nearest of ~100 points of presence, so the shaky part of the journey (their home internet) is as short as possible. From there the video rides a private backbone.
Media proxy
Terminates RTMP (or WebRTC), checks the stream key and converts to one internal format. It then asks the routing service which origin should process this stream.
Ingest routing
Picks an origin data centre for each stream using live capacity of transcoders and the backbone, and reroutes when an origin fails. Fixed regional assignment wasted capacity.
Origin & network capacity
Real-time view of spare transcoding and network capacity per origin, fed by the origins themselves.
Transcoders (origin)
Decode the source once and encode several renditions (1080p60, 720p, 480p, 160p) so viewers on any connection can watch. This is by far the most expensive step, which is why not every channel always got every quality.
HLS segments & playlists
Each rendition is cut into segments of about two seconds plus a playlist file listing the newest ones. Segments are only useful for a minute, then expire (or are kept for VODs).
Live channel registry
Which channels are live right now and at which origin. Updated the moment a stream starts or stops.
Viewers
Players poll a playlist every couple of seconds and download the newest segments. One popular stream can have hundreds of thousands of them.
Edge cache
Thousands of viewers ask for the same two-second segment at the same moment; the edge fetches it once and serves everyone. Without this, popular streams would overwhelm the origin.
API gateway
Front door for non-video calls: channel pages, follows and the playback token.
Playback API
Checks whether the viewer may watch (subscriber-only, region) and returns a signed playlist URL for the right origin.
Channels & users
Channel settings, users, follows and subscriptions.
Learn more
- How Does Live Streaming Platform Work? (YouTube live, Twitch, TikTok Live) (ByteByteGo)
- 25: Live Streaming (Twitch) | Systems Design Interview Questions With Ex-Google SWE (Jordan has no life)
- Its all WebSockets! - Devtooling Twitch (Hussein Nasser)
- Ingesting live video streams at global scale (Twitch Blog)
- Live video transmuxing/transcoding: FFmpeg vs TwitchTranscoder (Twitch Blog)
- HTTP Live Streaming (Apple Developer)