failover
← All labs

Medium · 12 steps · ~75 min

Design a chat app

Messages delivered in order, with ticks, to phones that are often offline.

Chat needs open connections for instant delivery, but a phone may be offline, so messages must be stored until delivered.

Same problem as WhatsAppTelegramSignal

How it works

What you'll build

  1. The API and the data behind it
  2. A gateway and a database for 500 requests a second
  3. A queue, workers and a cache for 15,000, then 50,000
  4. A rate limiter that stops a spam flood
  5. A design that survives a cold cache, a lost gateway, a lost worker and a lost primary

Steps

  1. 1Design the API
  2. 2Design the data model
  3. 3Handle 500 messages/sec
  4. 4Handle 15,000 requests/sec for $1,400 a month
  5. 5Handle 50,000 requests/sec
  6. 6Survive a spam flood on a budget
  7. 7Survive a cache restart
  8. 8Lose a realtime gateway
  9. 9Lose a worker
  10. 10Lose the primary database
  11. 11Messages arrive twice and out of order
  12. 12Deep dive: pushing to an offline phone
Start the lab →