Skip to main content

Classic design · Senior

Live streaming (Twitch)

Classic interview design. Key points: blob and video delivery, and WebSocket and presence.

16 min read · Content reviewed on October 23, 2026

Short answer

Classic interview design. Key points: blob and video delivery, and WebSocket and presence. A live streaming platform receives video from broadcasters and delivers it, live, to many viewers. Twitch describes, in an engineering post, a peak of tens of thousands of simultaneous broadcasts delivered to viewers worldwide.

01 · CONTEXT AND REQUIREMENTS

Two paths in one product: video and chat

A live streaming platform receives video from broadcasters and delivers it, live, to many viewers. Twitch describes, in an engineering post, a peak of tens of thousands of simultaneous broadcasts delivered to viewers worldwide. Broadcasters send video over RTMP, and to scale delivery to many viewers Twitch uses HLS.

To study the problem, it is worth separating two paths: the video path, which carries many bytes from one broadcaster to many viewers, and the chat path, in which each viewer also sends messages. The two have different requirements and are designed separately.

02 · FROM INGEST TO PLAYER

The video path

RTMP was designed to stream video and audio over the internet and is used mainly in point-to-point communication. HLS, in turn, delivers video over HTTP and is compatible with large-scale HTTP cache infrastructure, which supports delivery to large audiences.

In the middle of the path sits the transcoder. It converts the incoming RTMP stream into HLS with several variants, each with a different bitrate, so that viewers with different bandwidths watch at the best quality possible for their connection. A master playlist gathers the variants, and the player switches between them to adapt to the network.

  1. The broadcasting software sends the video to the ingest server over RTMP.

    Architecture diagram: Live: from ingest to player
    CLTransmissor
    CPIngest server
    CPTranscodificador
    DBOrigem HLS
    EDGCDN edge
    CLPlayer
  2. The transcoder converts the incoming RTMP stream into HLS, with several bitrate variants.

    Architecture diagram: Live: from ingest to player
    CLTransmissor
    CPIngest server
    CPTranscodificadorgenerates the variants
    DBOrigem HLS
    EDGCDN edge
    CLPlayer
  3. In this design, the segments and playlists of each variant are written to an origin, from which the CDN fetches them.

    Architecture diagram: Live: from ingest to player
    CLTransmissor
    CPIngest server
    CPTranscodificador
    DBOrigem HLSsegments and playlists
    EDGCDN edge
    CLPlayer
  4. In this design, the CDN edge caches playlists and segments and serves the players; HLS is compatible with HTTP cache infrastructure.

    Architecture diagram: Live: from ingest to player
    CLTransmissor
    CPIngest server
    CPTranscodificador
    DBOrigem HLS
    EDGCDN edgeedge cache
    CLPlayer
  5. The player receives the master playlist and switches between variants to adapt to network conditions.

    Architecture diagram: Live: from ingest to player
    CLTransmissor
    CPIngest server
    CPTranscodificador
    DBOrigem HLS
    EDGCDN edge
    CLPlayervariant switching

This first version shows the whole flow, but leaves open what happens inside the transcoder.

03 · TRANSCODING

Aligned variants and the cost of the transcoder

Transcoding costs in two ways. H.264 compression is lossy, so re-encoding degrades video quality, and encoding is a computationally very expensive process, especially at high resolution and high frame rate. That is why Twitch says the ideal would be to transmux, that is, pass through without decoding and re-encoding, the highest variant, saving computation and preserving quality.

The problem with transmux is alignment. The HLS specification requires that the IDR frames of corresponding segments in each variant be aligned, with the same Presentation Timestamp, and that is what lets the player switch variants seamlessly when the network changes. But the IDR interval of the source stream is set by the broadcasting software's configuration, outside the platform's control. If the source only undergoes transmux, there is no guarantee that the variants' segments align, and Twitch observed playback pauses on Chromecast with misaligned segments.

  1. The ingest receives the RTMP stream and hands it to the two processing paths.

    Architecture diagram: Live: source passthrough and re-encoded variants
    CPIngest server
    CPSource passthrough
    CPRe-encoding the others
    DBOrigem HLS
    CLPlayer
  2. The highest variant is only passed through, without re-encoding: it saves computation and preserves quality.

    Architecture diagram: Live: source passthrough and re-encoded variants
    CPIngest server
    CPSource passthroughtransmux
    CPRe-encoding the others
    DBOrigem HLS
    CLPlayer
  3. The other variants are re-encoded, and the encoder can force IDR at fixed intervals.

    Architecture diagram: Live: source passthrough and re-encoded variants
    CPIngest server
    CPSource passthrough
    CPRe-encoding the othersfixed IDR
    DBOrigem HLS
    CLPlayer
  4. At the origin, there is no guarantee that the passed-through variant's segments align with those of the re-encoded ones.

    Architecture diagram: Live: source passthrough and re-encoded variants
    CPIngest server
    CPSource passthrough
    CPRe-encoding the others
    DBOrigem HLSno alignment guarantee
    CLPlayer
  5. The alignment that allows switching variants seamlessly is not guaranteed; Twitch reports playback pauses on Chromecast with misaligned segments.

    Architecture diagram: Live: source passthrough and re-encoded variants
    CPIngest server
    CPSource passthrough
    CPRe-encoding the others
    DBOrigem HLS
    CLPlayerpossible pauses
CriterionTransmux of the highest variantTranscode all variants
QualidadePreserves the source qualityRe-encoding degrades quality
Compute costSaves computationEncoding is very expensive
Segment alignmentNo alignment guaranteeSegments perfectly aligned in time

There is also the cost of generating several variants. The simplest way is to create N independent transcoders, one per variant, but the ideal would be to eliminate redundant decoders and feed the rest of the pipeline with the images decoded by just one. Resizing is also expensive, and avoiding repeating it unnecessarily significantly improves performance. Since the encoder and scaler are very expensive, Twitch highlights the use of multi-core CPUs to process several variants at the same time.

FFmpeg does not meet some specific technical requirements of Twitch's operation, and the series of posts explains why it builds its own transcoder. With its own transcoder and player, the company controls the complete pipeline of ingest, transcoding, CDN, and playback.

04 · LIVE PLAYLIST

How the player follows an endless stream

In a live broadcast the playlist is not fixed: the client must reload it periodically to know which media is available, discovering the added segments. Per the HLS RFC, if the playlist changed the client waits at least the target duration before reloading; if it did not change, it waits half the target duration before trying again.

On the server side, while the broadcast has not ended, each new version of the playlist must bring at least one new segment and come out between half and one and a half times the target duration after the previous one. The server may limit segment availability by removing segments from the playlist, but a removed segment must remain available for a while, so as not to interrupt those still playing it.

  1. The player requests the variant's playlist from the CDN edge.

    Architecture diagram: Live: from ingest to player
    CLTransmissor
    CPIngest server
    CPTranscodificador
    DBOrigem HLS
    EDGCDN edge
    CLPlayer
  2. In this design, the edge fetches from the origin the playlist and segments it does not yet have cached.

    Architecture diagram: Live: from ingest to player
    CLTransmissor
    CPIngest server
    CPTranscodificador
    DBOrigem HLS
    EDGCDN edge
    CLPlayer
  3. The server publishes new versions of the playlist, each with at least one new segment.

    Architecture diagram: Live: from ingest to player
    CLTransmissor
    CPIngest server
    CPTranscodificador
    DBOrigem HLSupdated playlist
    EDGCDN edge
    CLPlayer
  4. The player waits at least the target duration before reloading the playlist and, if it has not changed, half the target duration.

    Architecture diagram: Live: from ingest to player
    CLTransmissor
    CPIngest server
    CPTranscodificador
    DBOrigem HLS
    EDGCDN edge
    CLPlayerrecarrega

The player, for its part, must not choose a segment that starts less than three target durations from the end of the playlist, because that can cause stalls. It also must not reload playlists of variants it is not playing, to reduce load on the server.

AspectoBroadcast in progressBroadcast ended
End of playlistWithout EXT-X-ENDLIST, the server publishes versions with new segmentsWith EXT-X-ENDLIST, no more segments will be added
Reload by the clientThe client must reload periodicallyThe client can minimize unproductive reloads

05 · CHAT

Long-lived connections, bursts, and limits

For chat, the WebSocket RFC summarizes the earlier problem: bidirectional applications required abusing HTTP with polling to receive updates and separate HTTP calls to send, and every message from client to server carried an HTTP header. The proposal is a single TCP connection for traffic in both directions.

Twitch chat is exposed as an IRC interface based on a modified RFC1459 and the IRCv3 tags specification, and WebSocket clients connect over wss on port 443. The documentation recommends using EventSub subscriptions and API calls instead of IRC, which has limitations and is more complicated to parse.

Long-lived connections need maintenance. The server sends PING to find out whether the client is alive and closes the connection if it does not receive PONG. When it has to close for maintenance, it sends RECONNECT, and the normal path is to reconnect and rejoin the channels. The documentation also warns that message order is not guaranteed and that a message may be sent more than once.

  1. Each viewer keeps a persistent connection to a chat server, chosen by the connection balancer.

    Architecture diagram: Live: chat with persistent connections
    CLEspectadores
    NWConnection load balancerdistributes connections
    CPChat servers
    CHRoom state
    QRoom bus
  2. On receiving a message, the server checks the room state, for example whether slow mode is on.

    Architecture diagram: Live: chat with persistent connections
    CLEspectadores
    NWConnection load balancer
    CPChat servers
    CHRoom stateroom modes
    QRoom bus
  3. In this design, if the message passes the room's rules, the server publishes it to the room bus.

    Architecture diagram: Live: chat with persistent connections
    CLEspectadores
    NWConnection load balancer
    CPChat servers
    CHRoom state
    QRoom buspublicada
  4. In this design, the bus delivers the message to all servers with viewers of the room, and each one relays it to its clients.

    Architecture diagram: Live: chat with persistent connections
    CLEspectadores
    NWConnection load balancer
    CPChat serversrepassa
    CHRoom state
    QRoom bus
  5. During maintenance, the server sends RECONNECT; the client's normal path is to reconnect and rejoin the room.

    Architecture diagram: Live: chat with persistent connections
    CLEspectadores
    NWConnection load balancer
    CPChat serversasks to reconnect
    CHRoom state
    QRoom bus

Chat also has limits. Messages sent in rapid succession are silently dropped by the server, which may even close the connection. In rooms with more than a thousand users, the bot stops receiving JOIN and PART messages. And moderators can enable room settings, such as slow mode and followers-only mode, which the server announces with ROOMSTATE.

06 · SUMMARY

Two paths, two protocols

AspectoVideoChat
Client protocolHLS over HTTPIRC over WebSocket
Leverage point for scalingCompatible with large-scale HTTP cacheA single TCP connection in both directions
How data comes inRTMP, used mainly in point-to-point communicationwss on port 443 for WebSocket clients

Frequently asked questions

What is Live streaming (Twitch)?

Classic interview design. Key points: blob and video delivery, and WebSocket and presence.

What does the Live streaming (Twitch) design cover?

It is organized in these sections: Two paths in one product: video and chat, The video path, Aligned variants and the cost of the transcoder, How the player follows an endless stream, Long-lived connections, bursts, and limits, and Two paths, two protocols.

How long is Live streaming (Twitch) and what level is it?

It takes about 16 minutes to read and is rated Senior level.

Now design it yourself

Run this case as an interview in the System Design school: you make the decisions, the tutor challenges them and you see how your design scores.