Solved design · 10 of 12 · 10 credits, once

Twitch

Broadcasters push into live ingest and transcoders; viewers pull segments through a CDN with short-TTL manifests; chat fans out through Kafka to room pub/sub.

Template
Twitch
Level
Advanced
Reading time
18 min
Topics
Live videoIngest and transcodingCDNChat fan-outPub/subShort TTLs

In the lab Broadcasters push into live ingest and transcoders, viewers pull segments through a CDN with short-TTL manifests, chat fans out through Kafka to room pub/sub. It meets its goals as given (success ≥ 99%, p99 ≤ 2 s, Apdex ≥ 0.90). Open it to see how it is put together, then push it: 3x traffic, an attack, a flush, a dead replica, and fix what breaks.

1Context and scope

Live video is two very different workloads. A few thousand broadcasters push continuous streams that must be transcoded into renditions and packaged into segments within seconds. Millions of viewers pull those segments and a playlist that changes every few seconds, and chat in rooms where one message reaches everyone watching. This design covers ingest, playback manifests and chat at browser scale, based on Twitch’s engineering posts.

2Goals and non-goals

Goals

  • 8,000 requests a second: 85% playback, 14% chat messages, 1% ingest.
  • Success at least 99%, p99 at most 2 s (ingest requests are slow by nature), Apdex at least 0.90.
  • Chat messages fan out to rooms with nothing lost.

Non-goals

  • Video bytes: the CDN serves segments.
  • Clips, VODs and subscriptions.
  • Moderation and bots.

3Capacity estimate

QuantityValueHow
Served at the CDN90% of readssegments are cacheable; manifests less so
Manifest cache4 GB, 200K streams, 30 s TTLa live playlist changes every few seconds
Chat messages≈ 1,120/s14% of 8,000, through 64 Kafka partitions
Chat fan-out256 workers at ≈ 2 mspublishes each message to its room topic
Ingest≈ 80/seach: a transcode (1.5 s, 800 ms CPU) and a segment write
Transcoders400 slots, 400 vCPU80 × 1.5 s = 120 slots busy; 80 × 0.8 = 64 vCPU busy

The rest of the doc

The design · Key concepts · Alternatives considered · Failure modes and fixes · Try it in the lab · Check yourself · Further reading

Solved design · 10 credits, once

Unlock the Twitch design doc

Every component and why it is there, the capacity numbers behind it, what breaks when you push it and how to fix it, and the same system open in the lab to break and fix yourself. Paid once, on your account.