Problems / Async and streaming, hard
Asked at YouTube and Twitter/X. Each view increments a per-video counter row in a key-value store, and the trending page reads those counters. Views follow a power law, so one viral video hammers one partition; at 10 s a new release doubles views.
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.
Success ≥ 99.5%, p99 ≤ 400 ms and Apdex ≥ 0.90, for at most $26,000 a month.
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 3; 1 of them are hidden until then.
30,000 requests a second for 20 seconds: 90% view (writes), 10% trending (reads).
What each component does in this design, and what calls it. The simulator mimics each one from these settings.
| Component | Its job here | Settings |
|---|---|---|
| Load balancerLoad balancer | Traffic enters here.Calls View API, Trending API.Layer 4 balancers route by IP and port; layer 7 balancers read HTTP and can route by path or header. | – |
| View APIApp service | Load balancer forwards to it for /view.Calls View counters (DynamoDB, one row per video).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 |
| Trending APIApp service | Load balancer forwards to it for /trending.Calls View counters (DynamoDB, one row per video).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 |
| View counters (DynamoDB, one row per video)Key-value store | View API calls it. Trending API calls it.Key-value stores spread keys over partitions; one very popular key can overload a single partition. | 32 partitions × 2,000 ops/s |