Problems / Real world, hard

YouTube end to end

20,000 requests/s routed by path: watch, search, comments and uploads. Metadata cache in front of Vitess MySQL, recommendations, view events into Kafka, uploads to storage and a transcoding queue.

Free to open. Runs in your browser, no sign-up.

Your goals

Keep success ≥ 99%, p99 ≤ 500 ms and Apdex ≥ 0.90. Then push it: 3x traffic, a DDoS, a cache flush. Find what breaks first and fix it.

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 Media CDN.Volumetric floods are absorbed at the network edge, spread over many locations, before they reach you.100000 slots
Media CDNCDNDDoS protection forwards to it.Calls API gateway.A CDN keeps copies at edge locations near users, so a cache hit skips the trip to your origin.–
API gatewayAPI gatewayMedia CDN 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 Metadata cache (Redis) (checked first), Recommendations (gRPC), View events (Kafka) (publishes).Little's law: throughput ≈ concurrency ÷ latency. 200 slots at 50 ms serve about 4,000 req/s.12 replicas × 100 slots · timeout 1.0 s
Metadata cache (Redis)CacheWatch API checks it first for reads.An in-memory cache like Redis usually answers in well under a millisecond inside one region.64 GB memory
Video metadata (Vitess MySQL)SQL databaseWatch API reads it when Metadata cache (Redis) misses.Postgres runs one process per connection, which is why poolers like PgBouncer sit in front of busy databases.64 vCPU · 1000 connections · 4 read replicas
Recommendations (gRPC)gRPC serviceWatch API calls it.gRPC uses HTTP/2 and Protocol Buffers for compact, typed calls between services.1000 slots
Encoder farmVideo transcoderTranscode workers calls it.Transcoding turns one video into several resolutions for adaptive streaming.1800 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.64 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.96 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.2000 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.6 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.512 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.4 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.400 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.4 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.5000 slots · 600,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.1800 concurrent jobs

More real world problems