Problems / Real world, hard
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.
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.
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.
20,000 requests a second for 20 seconds: 80% watch (reads), 12% search (reads), 6% comment (writes), 2% upload (writes).
What each component does in this design, and what calls it. The simulator mimics each one from these settings.
| Component | Its job here | Settings |
|---|---|---|
| DDoS protectionDDoS protection | Traffic 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 gateway | DDoS 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 service | API 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 database | Watch 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 service | Watch API calls it.gRPC uses HTTP/2 and Protocol Buffers for compact, typed calls between services. | 125 slots |
| Encoder farmVideo transcoder | Transcode workers calls it.Transcoding turns one video into several resolutions for adaptive streaming. | 225 slots |
| View events (Kafka)Event stream | Watch 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 counterWorker | View 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 database | View counter calls it.Time-series databases compress by time and downsample old data to keep storage small. | 250 slots |
| Search APIApp service | API 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 index | Search API calls it.Search engines build an inverted index: each word points to the documents that contain it. | 64 slots |
| Comments APIApp service | API 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 database | Comments API calls it.Document databases store nested JSON-like records, so one read can fetch a whole aggregate. | 50 slots |
| Upload APIApp service | API 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 storage | Upload 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 queue | Upload API publishes to it.Calls Transcode workers.If a consumer does not finish within the visibility timeout, the message is delivered again. | – |
| Transcode workersWorker | Transcode 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 |