Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 05

Design a chat app

Intermediate · 40 min · Real-time delivery

Two people message each other from their phones. Phones drop off the network all the time, sometimes right after tapping send and before hearing back, and people expect every message to show up exactly once, in the same order on both screens, even after a long time offline.

Requirements

  • Send and receive text messages in one-to-one conversations.
  • Keep message history and let a client catch up on everything it missed after a disconnect.
  • A send that is retried after a timeout must never show up as a second message.
  • Show the sender when a message has been stored by the server and when it has reached the recipient's device.

Constraints and assumptions

  • 100 million daily active users sending about 40 messages each a day: roughly 46,000 messages per second on average and 150,000 at peak.
  • Up to 30 million clients connected at the same time over long-lived connections.
  • Messages are text, at most 4 KB, about 100 bytes on average. History is kept indefinitely.
  • When both people are online, a message should appear on the recipient's screen within 500 ms at p99.
  • Assume a client can drop and reconnect at any point, including after sending but before receiving an acknowledgement. Start with one device per user.

Out of scope for the first sketch

Group conversations · Photos, voice notes and other media · End-to-end encryption, typing indicators and online presence

Draw your design

Rough math and notes

Done on paper? Compare with the worked approaches