Problems / Real world, hard

Slack: from launch build to real traffic

Slack as first built: channel history read straight from MySQL with no cache, no read replicas, and the message, history and presence services, fan-out workers and search at an eighth of their real size. 5,000 requests a second: 45% reading history, 40% sending messages that fan out to channels, search and push, 15% presence. Messages and history time out.

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 5,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

5,000 requests a second for 20 seconds: 45% reads, 40% send (writes), 15% presence (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 History API, Message API, Presence API.Gateways centralise auth, rate limits and routing so each service does not reimplement them.50000 slots · 1,200,000 calls/min
Message APIApp serviceAPI gateway forwards to it for /send.Calls Messages (MySQL, sharded by workspace), Message 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
Messages (MySQL, sharded by workspace)SQL databaseMessage API calls it. History API calls it for reads.Postgres runs one process per connection, which is why poolers like PgBouncer sit in front of busy databases.6 vCPU · 75 connections
Message events (Kafka)Event streamMessage API publishes to it.Calls Real-time fan-out.Kafka keeps order only within a partition, so the partition key decides what stays in sequence.8 partitions · retention 600 s
Real-time fan-outWorkerMessage events (Kafka) consumes from it.Calls Channel pub/sub (to WebSocket servers), Message search index, Mobile push.Queues deliver at least once, so a worker can see the same message twice.32 concurrent jobs
Channel pub/sub (to WebSocket servers)Pub/sub topicReal-time fan-out calls it.Pub/sub delivers each message to every subscriber, so producers never know who listens.1250 slots
Message search indexSearch indexReal-time fan-out calls it.Search engines build an inverted index: each word points to the documents that contain it.32 slots
Mobile pushNotification serviceReal-time fan-out calls it on 30% of requests.Email, SMS and push providers all throttle senders and can delay delivery.25 slots · 250,000 calls/min
History APIApp serviceAPI gateway forwards to it for /read.Calls Messages (MySQL, sharded by workspace).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
Presence APIApp serviceAPI gateway forwards to it for /presence.Calls Presence service.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
Presence servicePresence servicePresence API calls it.Presence is a heartbeat: each client pings every few seconds, and a status flips to away when the pings stop.625 slots

More real world problems