Problems / Real world, hard

Instagram: from launch build to real traffic

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.

Your goals

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.

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

4,000 requests a second for 20 seconds: 70% feed (reads), 10% profile (reads), 15% like (writes), 5% post (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 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 serviceAPI 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 storeFeed 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 modelFeed 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 serviceAPI 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 databaseProfile 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 serviceAPI 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 storeLikes 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 serviceAPI 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 storagePost 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 processingPost API calls it.Resizing images is CPU-heavy, so it is usually done once and cached.50 slots
Fan-out jobsMessage queuePost 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 workersWorkerFan-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 serviceFan-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

More real world problems