Problems / Real world, hard

YouTube: from launch build to real traffic

YouTube as first built: no media CDN, no metadata cache in front of Vitess MySQL, and the watch, search, comment and upload services, recommendations, view counting and transcoding at an eighth of their real size. 20,000 requests a second arrive, routed by path. Almost everything fails.

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 20,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

20,000 requests a second for 20 seconds: 80% watch (reads), 12% search (reads), 6% comment (writes), 2% upload (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 Watch API, Search API, Comments API, Upload API.Gateways centralise auth, rate limits and routing so each service does not reimplement them.50000 slots · 3,000,000 calls/min
Watch APIApp serviceAPI gateway forwards to it for /watch.Calls Video metadata (Vitess MySQL), Recommendations (gRPC), View events (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
Video metadata (Vitess MySQL)SQL databaseWatch API calls it for reads.Postgres runs one process per connection, which is why poolers like PgBouncer sit in front of busy databases.8 vCPU · 125 connections
Recommendations (gRPC)gRPC serviceWatch API calls it.gRPC uses HTTP/2 and Protocol Buffers for compact, typed calls between services.125 slots
Encoder farmVideo transcoderTranscode workers calls it.Transcoding turns one video into several resolutions for adaptive streaming.225 slots
View events (Kafka)Event streamWatch API publishes to it.Calls View counter.Kafka keeps order only within a partition, so the partition key decides what stays in sequence.8 partitions · retention 600 s
View counterWorkerView events (Kafka) consumes from it.Calls View counts (Bigtable).Queues deliver at least once, so a worker can see the same message twice.12 concurrent jobs
View counts (Bigtable)Time-series databaseView counter calls it.Time-series databases compress by time and downsample old data to keep storage small.250 slots
Search APIApp serviceAPI gateway forwards to it for /search.Calls Search index.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
Search indexSearch indexSearch API calls it.Search engines build an inverted index: each word points to the documents that contain it.64 slots
Comments APIApp serviceAPI gateway forwards to it for /comment.Calls Comments store.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
Comments storeDocument databaseComments API calls it.Document databases store nested JSON-like records, so one read can fetch a whole aggregate.50 slots
Upload APIApp serviceAPI gateway forwards to it for /upload.Calls Video storage (GCS), Transcode jobs (publishes).Little's law: throughput ≈ concurrency ÷ latency. 200 slots at 50 ms serve about 4,000 req/s.1 replicas × 100 slots · timeout 5.0 s
Video storage (GCS)Object storageUpload API calls it. Transcode workers calls it.Object stores like S3 keep copies across devices and facilities for very high durability.625 slots · 75,000 calls/min
Transcode jobsMessage queueUpload API publishes to it.Calls Transcode workers.If a consumer does not finish within the visibility timeout, the message is delivered again.–
Transcode workersWorkerTranscode jobs consumes from it.Calls Encoder farm, Video storage (GCS).Queues deliver at least once, so a worker can see the same message twice.225 concurrent jobs

More real world problems