Skip to content
System Design Explorer
Company architectureadvanced

Twitch System Design

Live video: ingest at ~100 PoPs, transcode at origins, watch in seconds

By Ankur NayakReviewed

How Twitch takes a live stream from a broadcaster's PC to millions of viewers a few seconds later: the stream enters at one of nearly a hundred points of presence, a routing service picks an origin with spare transcoding capacity over Twitch's private backbone, the origin turns it into several bitrates, and viewers watch over low-latency HLS.

Open in Studio· edit a copy
Users
1.5M+ streaming at any moment (2021)
Points of presence
~100
Latency
~3 s
Creators
2.2M+ a month
Hardware transcoding
10x capacity, 2x cost
Twitch system design architecture diagramComponents: Broadcaster (RTMP), PoP Media Proxy (Intelligest), Ingest Router (Intelligest), Origin Transcoding, Delivery PoPs, Viewer's Player (Low-latency HLS), Local ISPs, Hardware Transcoders. Connections: Broadcaster to PoP Media Proxy (live stream); PoP Media Proxy to Ingest Router (which origin?); PoP Media Proxy to Origin Transcoding (private backbone); Origin Transcoding to Delivery PoPs (backbone); Delivery PoPs to Viewer's Player (segments); Delivery PoPs to Local ISPs (partner networks); Origin Transcoding to Hardware Transcoders (renditions).BroadcasterRTMPPoP Media ProxyIntelligestIngest RouterIntelligestOrigin TranscodingWorkerDelivery PoPsCDNViewer's PlayerLow-latency HLSLocal ISPsExternal APIHardware TranscodersWorker

Requirements

Functional

  • Accept live streams from broadcasters anywhere (RTMP, WebRTC)
  • Transcode each stream into several bitrates and resolutions
  • Deliver streams to viewers on any device and network
  • Let a channel go from a few viewers to millions

Non-functional

  • Seconds of delay between broadcaster and viewer
  • Use transcoding capacity efficiently at peak
  • Route around failed origins and network links automatically
  • Smooth playback despite network jitter

In depth

Live video, seconds behind reality

On Twitch, a streamer talks to their audience and the audience answers in chat, so delay matters. Twitch says more than 1.5 million people are streaming at any given moment, across hundreds of thousands of live channels, and a big channel can go from nothing to a few million viewers when it goes live. Every one of those streams has to be received, transcoded into several qualities and delivered worldwide within a few seconds.

Twitch has described its system in three posts: its 2017 comparison of FFmpeg with its own transcoder, a 2021 interview about its delivery network, and a detailed 2022 post on how live streams are ingested. Twitch describes its approach as vertically integrated: it owns each step, from the point where a stream enters to the player.

Ingest: points of presence and a private backbone

A broadcaster streams from software like OBS, typically using RTMP: for example, 1080p at 60 frames per second and 6 Mbps. The stream enters Twitch at one of nearly a hundred points of presence (PoPs) around the world. Each PoP is connected to Twitch's private backbone network, which links it to origin data centres, where the computationally intensive work, chiefly transcoding, happens.

Twitch began with a single origin in Silicon Valley; today origins are spread around the world. That raises the central ingest question: for each new stream, which origin should process it?

Intelligest: routing every new stream

For years every PoP ran HAProxy and forwarded streams according to a routing plan computed offline with an optimisation solver. That plan was static, so it couldn't handle unexpected traffic patterns or failures well. Twitch replaced it with Intelligest, which has two parts:

  • An Intelligest media proxy in every PoP terminates media protocols such as RTMP or WebRTC.
  • The Intelligest Routing Service (IRS), running in AWS, is the routing controller. For each new stream, the proxy asks IRS where to send it.

IRS has a real-time view of the infrastructure from two systems: Capacitor, which monitors compute resources in every origin, and The Well, which monitors the backbone and reports the status of its links. With those inputs, IRS uses a randomized greedy algorithm to choose an origin. Twitch reports that Intelligest lets it use 100% of its available compute at peak times, and that when something goes wrong, IRS automatically directs new streams to unaffected origins.

Intelligest decides where streams go; it doesn't control the backbone's own network-layer routing.

Transcoding: many renditions from one stream

Viewers have every kind of connection, so each stream is converted into several renditions, and the player picks one: adaptive bitrate streaming. Twitch's 2017 post shows a 1080p60 source turned into HLS variants such as 1080p60, 720p60, 720p30 and 480p30.

Twitch built its own TwitchTranscoder because FFmpeg couldn't meet some of its requirements. Two techniques stand out. The top rendition is transmuxed rather than transcoded: the video is repackaged from RTMP into HLS without decoding and re-encoding, avoiding quality loss and compute, though the source bitstream might not be perfectly HLS-compliant. The lower renditions are transcoded, with scaling as one of the most expensive steps; multithreading helps fit more streams on each machine. The transcoder also handles practical details such as converting 50 fps sources to 25 fps rather than 30.

Transcoding is expensive, and the 2021 post says that at one point Twitch could only offer it to 2 or 3 percent of channels. Hardware transcoding changed that: Twitch expanded capacity by 10 times at only twice the cost.

Delivery and latency

From origins, video travels over the backbone to PoPs and out to viewers, with Twitch partnering with local internet providers. Replicating every channel to every PoP would be a huge burden, so the PoP topology is designed carefully for reach and quality. Players keep small buffers to keep streams smooth.

Latency has fallen steadily. Twitch reduced it from about 15 seconds to about 10, and then built low-latency HTTP live streaming, cutting it to about 3 seconds, and around 1.5 seconds in some cases in Korea. Lower latency means smaller buffers, so the system has to be consistently fast. See CDN.

Failures

When an origin has problems, IRS sends new streams to unaffected origins. When a backbone link degrades, The Well reports it and routing takes it into account. When a giant channel goes live, the distributed PoPs, ISP partnerships and player buffers absorb the surge; Twitch's posts don't describe in detail how a single channel's replication scales.

The trade-offs

Real-time routing uses capacity far better than a static plan but puts a central service on the go-live path. Owning the whole pipeline gives control over latency and quality but means building and operating a global network. Transmuxing the top rendition saves compute and quality at the risk of spec compliance. And low latency brings streamers closer to their chat at the cost of less buffering against network hiccups.

Compare with YouTube in YouTube vs Twitch, where on-demand video can be processed at leisure.

What to take into an interview

  • Ingest at many PoPs close to broadcasters, over a private backbone to origins
  • Route each new stream dynamically by origin capacity and network health
  • Transcode into a ladder of renditions; transmux the top one when you can
  • Use HTTP-based segments (HLS) so delivery scales through PoPs and caches
  • Treat latency as a budget: segment size, buffer size and transcoding speed all spend it

Components

Broadcaster

RTMP

Client. Streams from OBS or a console to Twitch, typically over RTMP, e.g. 1080p60 at 6 Mbps.

PoP Media Proxy

Intelligest

Load balancer. Runs in each of nearly a hundred points of presence. Terminates media protocols such as RTMP or WebRTC and asks the routing service where to send the stream. Replaced HAProxy, which every PoP used to run.

Ingest Router

Intelligest

Coordination. The ingest routing controller: decides which origin should process each new live stream, using a randomized greedy algorithm over a real-time view of capacity and network health.

Why: A static, offline-computed routing plan couldn't handle unexpected traffic patterns; real-time decisions use all available capacity.

Routing Decision

Service. Randomized greedy algorithm choosing an origin for each new stream.

Capacitor

Monitoring. Monitors the compute resources in every origin.

The Well

Monitoring. Monitors the backbone network and reports the status of its links.

Origin Transcoding

Worker. Origin data centres host the compute-heavy media work. Twitch's own transcoder (TwitchTranscoder, built because FFmpeg fell short) transmuxes the top variant and transcodes lower ones into HLS, e.g. 720p60, 720p30 and 480p30.

Building block: Adaptive Bitrate Streaming

Delivery PoPs

CDN. Points of presence connected to the data centres by Twitch's backbone, partnering with local ISPs. Replicating every channel to every PoP would be a huge burden, so the topology is designed for reach and quality.

Building block: CDN

Viewer's Player

Low-latency HLS

Client. Plays HLS with a small buffer to stay smooth. Twitch's low-latency HLS cut delay from about 10 seconds to about 3.

Building block: Adaptive Bitrate Streaming

Local ISPs

External API. Twitch partners with local internet service providers to reach viewers.

Hardware Transcoders

Worker. Dedicated transcoding hardware that expanded Twitch's capacity by 10 times at only twice the cost; before it, Twitch could offer transcoding to only 2–3% of channels.

Request flows

Go live

  1. A streamer clicks Start Streaming; OBS connects over RTMP to the nearest point of presence.
  2. The PoP's media proxy asks the Intelligest Routing Service which origin should take the stream.
  3. The routing service, knowing current origin capacity and backbone health, picks one.
  4. The stream travels over Twitch's private backbone to that origin.
  5. The origin produces HLS renditions at several bitrates and sends them toward the delivery PoPs.

Watch a stream

  1. A viewer opens the channel; the player requests the stream from a nearby PoP.
  2. The PoP gets the channel's segments over the backbone.
  3. The player buffers a little and plays, about 3 seconds behind the broadcaster with low-latency HLS.
  4. If the viewer's bandwidth drops, the player switches to a lower bitrate.

Failure scenarios

What if: an origin has a problem?

The routing service automatically directs new live streams to an unaffected origin, using its real-time view of capacity and network status.

User impact: New streams start elsewhere. The post doesn't describe what happens to streams already on that origin.

  • Real-time routing by capacity
  • Many origins on the backbone

What if: a backbone link degrades?

The Well reports the link's status, and the routing service sends new streams from that PoP over healthy paths to other origins. (Intelligest doesn't control the backbone's own L3 routing.)

User impact: Possibly a farther origin for new streams.

  • Link monitoring (The Well)
  • Routing that accounts for network health

What if: a huge channel goes live?

A big channel can go from zero to a few million viewers at once. Twitch's PoP topology and partnerships with ISPs are designed for reach, and its players use buffers to stay smooth; how replication scales for one channel isn't described in detail.

User impact: Buffering at the edge if capacity can't keep up.

  • Widely distributed PoPs
  • Player buffers
  • ISP partnerships

Trade-offs

Dynamic routing instead of a static plan

Choose an origin for each new stream in real time from capacity and link health.

Pros
  • Uses all compute at peak
  • Handles unexpected traffic and failures automatically
Cons
  • A central routing service on the go-live path

Own the whole pipeline

Build a vertically integrated video system: ingest PoPs, backbone, transcoding and delivery.

Pros
  • Control over latency and quality end to end
  • Custom tools where off-the-shelf ones fall short (TwitchTranscoder)
Cons
  • Large infrastructure to build and operate

Transmux the top rendition

Pass the source through for the highest variant and transcode only the lower ones.

Pros
  • No quality loss or compute cost for the top variant
Cons
  • The source bitstream may not be fully HLS-compliant

Low latency vs smoothness

Use low-latency HLS but keep a small player buffer.

Pros
  • About 3 seconds of delay instead of 10 or more
Cons
  • Less buffer means less tolerance for network hiccups

Frequently asked questions

How does Twitch live streaming work?

A broadcaster sends a stream over RTMP to one of Twitch's nearly 100 points of presence. A routing service picks an origin data centre with capacity, the stream crosses Twitch's private backbone, the origin transcodes it into several bitrates as HLS, and viewers play it from nearby points of presence.

How does Twitch keep latency low?

Twitch developed low-latency HTTP live streaming, cutting the delay from about 10 seconds to about 3, and to around 1.5 seconds in some cases. Players keep small buffers to stay smooth, and the ingest, backbone and transcoding are all run by Twitch.

What is the difference between transmuxing and transcoding?

Transmuxing repackages the video into a new container (from RTMP to HLS) without decoding and re-encoding it, so there's no quality loss. Transcoding decodes and re-encodes it, for example to produce lower resolutions. Twitch transmuxes the top rendition and transcodes the lower ones.

How does Twitch decide where a stream is processed?

The Intelligest Routing Service, running in AWS, decides for each new stream. It uses Capacitor's view of compute in every origin and The Well's view of backbone links, and a randomized greedy algorithm to choose an origin.

Building blocks used

Sources