Problems / Real world, hard
Instagram as a small team first shipped it: no timeline or profile cache, no media CDN, and every service an eighth of its real size. Real traffic arrives: 4,000 requests a second, 70% feed loads, 10% profiles, 15% likes and 5% new posts with photos to resize. Feeds time out and photos stall.
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 4,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.
4,000 requests a second for 20 seconds: 70% feed (reads), 10% profile (reads), 15% like (writes), 5% post (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 Feed API, Profile API, Likes API, Post API.Gateways centralise auth, rate limits and routing so each service does not reimplement them. | 50000 slots · 1,000,000 calls/min |
| Feed APIApp service | API gateway forwards to it for /feed.Calls Timelines (Cassandra), Feed ranking model.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 |
| Timelines (Cassandra)Key-value store | Feed API calls it for reads. Fan-out workers calls it.Key-value stores spread keys over partitions; one very popular key can overload a single partition. | 16 partitions × 2,000 ops/s |
| Feed ranking modelRanking model | Feed API calls it.Feeds rank a few hundred candidates per load with a learned model; retrieval narrows millions of posts first. | 128 slots |
| Profile APIApp service | API gateway forwards to it for /profile.Calls Users and posts (Postgres, sharded).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 |
| Users and posts (Postgres, sharded)SQL database | Profile API calls it for reads. Post API calls it.Postgres runs one process per connection, which is why poolers like PgBouncer sit in front of busy databases. | 4 vCPU · 50 connections |
| Likes APIApp service | API gateway forwards to it for /like.Calls Like counters (Cassandra).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 |
| Like counters (Cassandra)Key-value store | Likes API calls it.Key-value stores spread keys over partitions; one very popular key can overload a single partition. | 8 partitions × 2,000 ops/s |
| Post APIApp service | API gateway forwards to it for /post.Calls Media storage (S3), Image resizing, Users and posts (Postgres, sharded), Fan-out 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 |
| Media storage (S3)Object storage | Post API calls it.Object stores like S3 keep copies across devices and facilities for very high durability. | 625 slots · 75,000 calls/min |
| Image resizingImage processing | Post API calls it.Resizing images is CPU-heavy, so it is usually done once and cached. | 50 slots |
| Fan-out jobsMessage queue | Post API publishes to it.Calls Fan-out workers.If a consumer does not finish within the visibility timeout, the message is delivered again. | – |
| Fan-out workersWorker | Fan-out jobs consumes from it.Calls Timelines (Cassandra), Push notifications.Queues deliver at least once, so a worker can see the same message twice. | 32 concurrent jobs |
| Push notificationsNotification service | Fan-out workers calls it on 20% of requests.Email, SMS and push providers all throttle senders and can delay delivery. | 25 slots · 250,000 calls/min |