Real-time Chat
Deliver messages instantly, in order, online or off.
Keep messages flowing through a gateway crash, a network partition and a message storm.
Everything rides persistent gateway connections behind an LB, with a queue decoupling delivery from the store. Route through a single edge and a partition takes you down — give yourself a second path.
Components in play
- Edge LB — Distributes new connections.
- WS gateways — Hold the live sockets; fan messages out.
- Delivery queue — Decouples delivery from the store; keeps order.
- Message store — Append-only, partitioned history.
Graded on these SLOs
- ≥ 95.00%Messages delivered
- ≤ 150 msDelivery p99
- ≥ 9.0k rpsCarry the load
- ≤ 90%Gateway headroom
The brief
Design a messaging system like WhatsApp or Slack: 1:1 and group chats, delivery/read receipts, presence, and history. Messages must arrive in real time and in order, and reach users who are currently offline.
Functional
- 1:1 and group messaging
- Delivery & read receipts, presence
- Persisted, ordered message history
Non-functional
- Real-time, low-latency delivery
- Per-conversation ordering
- Handle offline recipients (store & forward)
Read the deep dive
16 min readA chat system looks deceptively simple — just send a string from A to B — but it is one of the densest interview problems because every hard distributed-systems concept shows up at once: persistent connections, ordering, exactly-once-ish delivery, fan-out, presence, offline handling, and graceful behaviour under partition. What makes it distinctive is that the connection is long-lived and bidirectional. Unlike a request/response API where the server can forget you the moment it answers, a chat server must hold your socket open, know which server holds the recipient's socket, and route a message across that mesh in tens of milliseconds — or stash it durably if the recipient is offline. This guide walks you from a blank canvas to the reference design the SysGym simulator grades against. The simulator models one cell carrying about 9,000 message-delivery events per second, and it grades four things: messages delivered (availability at or above 95 percent), delivery p99 at or below 150 ms, sustained throughput at or above 9,000 rps, and gateway saturation at or below 90 percent. Its scripted chaos — a gateway crash, a load-balancer-to-gateway network partition, and a queue latency spike, all on top of a group that goes off and multiplies load by 1.5x — is engineered so that only a design with two independent gateway paths, each sized to carry the whole surge alone, survives. We will derive exactly why.
Warm-up: design decisions
Optional theory to prime the calls a senior engineer would make before you build.
Solving is a Pro feature
Unlock the on-canvas AI design coach, per-run design reviews, the chaos simulator and all 12 problems for $15/month.
- AI design coach on your canvas — pins failure points & over-engineering
- Honest AI design review on every run
- All 12 problems + unlimited chaos simulator
- Points, levels & leaderboard