CSE Roadmap

Core tier · about 5 hours · 8 parts

Part 2 of 8 · 2 min read

Scope and numbers

What the chat must do, and how big it is.

Think of a telephone exchange. Each caller holds a line open, and the exchange must connect any two lines at once. A letter service, by contrast, only works when someone walks in. Chat is the exchange, not the letter service.

Questions and the answers assumed here (from the book's sample talk).

  1. One-to-one or group? Both.
  2. Mobile, web or both? Both.
  3. Scale? 50 million daily active users (DAU).
  4. Group size? Up to 100 people.
  5. Features? One-to-one chat, group chat, an online indicator. Text only.
  6. Message size? Under 100,000 characters.
  7. End-to-end encryption? Not now.
  8. History? Kept for ever.

Requirements.

  • R1. One-to-one chat with low delivery delay.
  • R2. Small group chat.
  • R3. Online presence.
  • R4. One account on several devices at once.
  • R5. Push notification when the user is offline.
  • R6. Messages stay in order and are not lost.

Numbers. The book notes that 1 million connected users at about 10 KB of memory each need about 10 GB. Scale this (made up). Suppose 10 per cent of 50 million are connected at peak, which is 5 million connections. At 10 KB each that is 50 GB of memory. If one server holds 50,000 connections, then 5,000,000 / 50,000 = 100 chat servers.

Message rate (made up). Each user sends 40 messages a day. That is 50,000,000 × 40 = 2,000,000,000 a day, or about 23,148 per second. At 100 bytes each, that is 200 GB a day, or about 73 TB a year, and history is kept for ever.

The key points: the hard part is the number of open connections, and the storage grows without end.

Persistent connection

A persistent connection stays open between messages, so either side can send at any moment without a new handshake.

Example: a phone keeps one connection to a chat server for the whole session and receives messages as they arrive.

Check yourself: 1. Why does chat need a connection that stays open? 2. What limits one chat server? 3. Why is storage a long-term concern?