Problems / Real world, hard

Twitch: from launch build to real traffic

Live streaming as first built: no manifest cache in front of the live streams catalog, and the playback and chat APIs, chat fan-out, live ingest and transcoders at an eighth of their real size. Real viewers arrive, watching and chatting, and three in four requests fail.

Unlock it once for 25 credits; everything inside it is free (runs, changes, Submit, results, hints). Sign in with Google to start; new accounts get free credits.

Your goals

Grow it into the real architecture: every goal must hold at 8,000 requests a second. You may add components, connect them and resize anything.

Test cases

Like a coding problem, a solution has to pass every case, not just the one it was built for. Submit in the lab runs all 6; 2 of them are hidden until then.

  1. As given. The problem’s own traffic, scheduled failures and seed.
  2. Peak hour. 25% more traffic than the problem states, with the same failures.
  3. A slow dependency. The main data store or model answers twice as slowly for part of the run.
  4. A server dies. One replica of the service with the most replicas is killed for part of the run.

The traffic

8,000 requests a second for 20 seconds: 85% watch (reads), 14% chat (writes), 1% ingest (writes).

The system

What each component does in this design, and what calls it. The simulator mimics each one from these settings.

ComponentIts job hereSettings
DDoS protectionDDoS protectionTraffic enters here.Calls API gateway.Volumetric floods are absorbed at the network edge, spread over many locations, before they reach you.100000 slots
API gatewayAPI gatewayDDoS protection forwards to it.Calls Playback API, Chat API, Live ingest (RTMP).Gateways centralise auth, rate limits and routing so each service does not reimplement them.50000 slots · 2,000,000 calls/min
Playback APIApp serviceAPI gateway forwards to it for /watch.Calls Live streams catalog.Little's law: throughput ≈ concurrency ÷ latency. 200 slots at 50 ms serve about 4,000 req/s.1 replicas × 100 slots · timeout 1.0 s
Live streams catalogDocument databasePlayback API calls it for reads.Document databases store nested JSON-like records, so one read can fetch a whole aggregate.100 slots
Chat APIApp serviceAPI gateway forwards to it for /chat.Calls Chat messages (Kafka) (publishes).Little's law: throughput ≈ concurrency ÷ latency. 200 slots at 50 ms serve about 4,000 req/s.1 replicas × 100 slots · timeout 1.0 s
Chat messages (Kafka)Event streamChat API publishes to it.Calls Chat fan-out.Kafka keeps order only within a partition, so the partition key decides what stays in sequence.8 partitions · retention 600 s
Chat fan-outWorkerChat messages (Kafka) consumes from it.Calls Chat room pub/sub (to edge servers).Queues deliver at least once, so a worker can see the same message twice.32 concurrent jobs
Chat room pub/sub (to edge servers)Pub/sub topicChat fan-out calls it.Pub/sub delivers each message to every subscriber, so producers never know who listens.2500 slots
Live ingest (RTMP)Live stream ingestAPI gateway forwards to it for /ingest.Calls Live transcoders, Segment storage.Broadcasters push RTMP or SRT to an ingest point near them; from there the stream is transcoded into renditions and packaged into segments.250 slots
Live transcodersVideo transcoderLive ingest (RTMP) calls it.Transcoding turns one video into several resolutions for adaptive streaming.50 slots
Segment storageObject storageLive ingest (RTMP) calls it.Object stores like S3 keep copies across devices and facilities for very high durability.625 slots · 250,000 calls/min

More real world problems