System Design Lab
A chat backend is a connection problem first: millions of live sockets must be tracked, then a message fanned out to everyone who should receive it.
Change concurrent connections, message rate, group size, the online ratio, history retention, devices per user, and regions. The design moves from a single socket server to a gateway fleet with a session registry, a routing and fan-out tier with a presence service, durable per-user inboxes, and finally cross-region routing with offline push.
Guided walkthrough
Reason about it one step at a time
Takeaway
Normal evolution scenarios
Click left to right for the intended demo path. Each card changes the workload inputs.
Recommended shape
Bottlenecks
Why this changes
Decision tradeoffs
Source-backed rules
These are the durable system-design claims behind the model. The exact slider thresholds are deliberately labeled as teaching assumptions.
A WebSocket is a persistent, full-duplex connection the server must keep open
Each chat client holds one long-lived connection, so the gateway tier is sized by how many open sockets it can keep in memory, not by request rate.
MDN Web DocsPublish/subscribe decouples senders from the many recipients of a message
Fan-out to a group is naturally a pub/sub problem: one publish is delivered to every subscriber, which is how a router expands a send to many members.
Google Cloud Pub/SubA durable message queue lets offline recipients receive messages later
A per-user inbox queue holds messages for disconnected or multi-device users until each device reconnects and drains its queue.
AWS SQSEnd-to-end encryption means the server routes ciphertext it cannot read
With E2EE the server can fan out and store messages but cannot inspect content, so server-side features must work on ciphertext and metadata only.
Signal ProtocolTeaching assumptions
- Each live socket is charged a fixed memory budget (kernel plus app buffers plus session state); real costs vary by stack.
- Fan-out rate is messages per second times average group size times devices per user; presence and receipts add return events on top.
- Single-node gateway, routing, inbox-write, and presence budgets are conservative teaching numbers, not vendor limits.