Messaging & realtime
Chat and messaging - one socket, many deliveries
Delivery guarantees, presence and ordering across devices.
The first act plays here. Owned once with credits, never a subscription.
What this board gets wrong on purpose
The tension
The connection tier is stateful and nothing else here is. A gateway holds its sockets in memory, so it cannot be rolled or scaled like the stateless services beside it - deploying gw-1 hangs up on everybody on gw-1 - and the presence registry that is the only record of which gateway holds you is a single store with no replica behind it.
Practise this as an interview
Take Chat and messaging - one socket, many deliveries as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.
Start here
Why this design
Chat is the standard question for testing whether a candidate can let go of request/response. The send path is easy; the hard parts are that the server must reach a person who asked for nothing, that the tier holding those connections is stateful while it looks like every other service, and that "delivered" is a claim about a screen the system cannot see. Interviewers use it to probe delivery guarantees, ordering and fan-out; teams that run chat learn the same lessons from their first gateway deploy, which hangs up on a hundred thousand people at once.
What you will learn
- Why the connection tier is stateful, and why a sticky load balancer balances once per connection rather than once per request - so load does not rebalance itself.
- Persist first, then fan out: why the message store is the delivery guarantee and every hop after it may fail and be retried.
- How a per-conversation sequence number (not arrival order, not a clock) gives every device the same order, and how gaps are detected and filled.
- The fan-out arithmetic - one send becomes ~5.6 device deliveries - and why large groups switch from push to pull.
- How the offline path works through APNs/FCM, and why a push notification is never a delivery receipt.
- How to roll a stateful gateway fleet: drain, jittered reconnects, admission control, and why the gateway should change rarely.
How to read this board
- Diagram, left to right: PEOPLE (a sender with an open socket, a recipient on two devices), then CONNECTION TIER · STATEFUL (Edge LB, gw-1, gw-2 and Presence), then CORE · STATELESS (Chat service, Message store, Fan-out, Delivery queue, Receipt writer).
- Then the band along the bottom, OFFLINE PATH · NO SOCKET TO PUSH DOWN: Push service and APNs / FCM, the only dashed wires. Press play for the eight-step walkthrough - one message, two endings.
- Page 1 · Requirements - the questions to ask first, and the latency and delivery targets the rest of the design is held to.
- Pages 2 and 3 · Capacity and Storage - messages per second, sockets, gateways, fan-out, and the bytes behind them.
- Page 4 · Availability - what happens when a gateway dies, when Presence dies, and what is shed first.
- Page 5 · How it works - the send path told end to end, including ordering, receipts and the offline device.
- Page 6 · Deployment plan - rolling the one tier that cannot simply be restarted, and running it in several regions.
1 · Requirements
Ask these before drawing anything
- One-to-one only, or groups? How big can a group get? Group size is the fan-out factor, and above a few hundred members the delivery model has to change from push to pull.
- Multi-device? If one person reads on a laptop and a phone, every message is delivered per DEVICE, receipts are per device, and a new device needs history - which decides whether the server keeps a log at all.
- Does the server keep history, or only hold messages until they are delivered? Store-and-forward is cheaper and more private; a server-side log is what makes multi-device sync and a new phone work. This board keeps the log.
- What does "delivered" mean - stored by us, received by a device, or painted on a screen? Pick one per tick and say it out loud.
- What order must two devices agree on? Total order per conversation is achievable; a global order across conversations is neither achievable nor needed.
- Is the content end-to-end encrypted? If yes the server routes opaque envelopes and cannot index, search or preview them, and push payloads carry no text.
- Are presence ("online", "last seen") and typing indicators in scope? They are the highest-volume, lowest-value traffic and the first thing to shed.
Functional
- Send a text message to a person or a group of up to 1,024 members; receive it live on every connected device.
- Deliver to devices that are offline via a platform push notification, and sync everything missed when the app next opens.
- Show sent (stored by us), delivered (acked by a device) and read (rendered on screen) per recipient.
- Keep a per-conversation history that a newly signed-in device can page backwards through.
- Show online / last-seen presence and typing indicators, best effort.
Non-functional
- Send acknowledged ("sent" tick) only after a quorum write: p99 under 300 ms from the sender's socket.
- Delivery to an online recipient in the same region: p50 under 100 ms, p99 under 500 ms end to end; cross-region p99 under 1 s.
- Zero loss once "sent" is shown. Delivery is at-least-once; the client de-duplicates by message id, so the user sees exactly once.
- Every device of every member renders a conversation in the same order (by sequence number), even when copies arrive by different paths.
- Reconnect and catch up on 1,000 missed messages in under 2 s on a mobile network.
- Sending: 99.99% available. Live delivery: 99.95%, falling back to sync-on-open when it is not. Presence and typing: no target - they may go dark.
Out of scope
- Media upload and storage, which is object storage plus a CDN and its own board.
- End-to-end key exchange (the Signal protocol) - assumed to exist; this board routes envelopes.
- Voice and video calls, search, spam and abuse classification.
The rest of this board
Available on Tier Slate
This page publishes the question. The answer — 5 more written pages and an 8-step narrated walkthrough — is the board itself, and it opens in Tierslate.
- 5written pages
- 8walkthrough steps
5 pages behind this one
- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan