Case study demo

Chat system

Send messages between users over persistent connections.

An interactive demo of how this system behaves. It runs in your browser.

Case study · Live model

How a chat system delivers messages

30 users on three chat servers, each phone with one open connection. Watch messages cross servers, wait for offline users, and survive a server crash.

Try it

Lab time 3.0 s
open connectionsPhones, 28 of 30 onlinePhones28 of 30 online3 messages/sServer S1, 10 phonesServer S110 phonesServer S2, 9 phonesServer S29 phonesServer S3, 9 phonesServer S39 phonesRouter & registry, who is whereRouter & registrywho is where17 passed onMessage store, every messageMessage storeevery message7 saved
  • Phones — 28 of 30 online — healthy — 3 messages/s
  • Server S1 — 10 phones — healthy
  • Server S2 — 9 phones — healthy
  • Server S3 — 9 phones — healthy
  • Router & registry — who is where — healthy — 17 passed on
  • Message store — every message — healthy — 7 saved
  • Message sent
  • Saved and numbered
  • Passed to another server
  • Pushed to a phone
  • Caught up after reconnecting
Online
28 of 30
Deliveries
6.3/s
3.6 due per message sent; 17 through the router
Typical delivery
130 ms
illustrative
Waiting for offline users
1
1 notifications sent
Missing on phones
0
Healthy: every online phone is up to date; caught up on reconnect: 0
Repeats
2
0 shown twice, 2 ignored

Numbers add up:25 deliveries due = 19 delivered + 5 on the way + 1 waiting for offline users + 0 lost while offline + 0 missing on online phones; every message is saved before "sent"; numbers in each conversation have no gapsThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

Messages
3 a second
30%

Groups have 8 members.

5%

A lost reply makes the server push the message again.

Phones

A reconnecting phone asks, in each conversation, for every message after its last number with no gap.

A phone drops a message id it already shows.

Servers

Ben's phone (u2) · connected to S2

MessageFromNumber in chatOn Ben's phone
#5u7 (group g2)1✓✓ delivered
#1u91✓✓ delivered

✓✓ means Ben's phone has it and replied "delivered". The number is the message's place in its conversation. On reconnect, a phone asks for everything after its last number with no gap before it.

Messages missing on online phones
00.30.50.811s2s3s
Show data table
TimeMissing
1s0
1s0
2s0
2s0
3s0
3s0

What just happened

  1. 0.0sInfo: 28 of 30 users are online, each with one open connection to a chat server.
What this model simplifies
  • Three servers and 30 users. Real services run thousands of servers, and a registry such as Redis tracks millions of connections.
  • Message times are illustrative: 40 ms between a phone and its server, 20 ms for each step through the router.
  • Read receipts, typing signs and end-to-end encryption are left out.
  • A reconnecting phone goes to the server with the fewest connections. Real load balancers also spread new connections this way.
  • A crashed server leaves the registry at once here. In real systems its entries stay until a heartbeat times out, so for a few seconds messages are still sent to the dead server.

Design it

Every message, once, even when a server fails

Thirty people chat in pairs and groups, through three chat servers. Some phones go offline, and some delivery receipts get lost, so the server sends a message again. Pick how the phones behave, then check the design.

The goals

  • After the crash, every online phone has every message sent to it.
  • No phone shows the same message twice.
When a phone reconnects
When a copy arrives twice

The check runs the same engine as the demo on this page for 30 simulated seconds under each condition, with a fixed seed, so a design always gets the same result. There is no score: each goal passes or fails.