Skip to content

Real-time & chat · 6 of 6

Step 1 · The pattern

One message in, a copy to everyone

A busy room produces chat messages and a stream of typing and presence signals. The gateway copies each one to every connected client. Each connection has a send buffer for copies the client has not taken yet. With fast clients, the buffers stay empty.

  • chat message
  • typing / presence
  • delivered

In short

Slow-client backpressure: how it works and how it breaks

A real-time gateway pushes each message to every client as it is produced. A client on a weak network reads slower than that, so the gateway keeps the unsent messages in that connection's send buffer. A short dip is fine: the buffer absorbs it and drains. The danger is a buffer with no limit. In a busy room a few slow clients each collect a growing backlog, the gateway's memory climbs, and the process is killed. That disconnects every client on it, including the ones that were keeping up. The fix is a limit per connection and a decision about what happens when it is reached. Drop or merge messages that lose their value quickly, such as typing and presence. If the client is still behind, close its connection. When it returns it fetches the current state instead of every message it missed.

How this comes up in interviews

"A gateway pushes every message in a busy room to each connected client. A few clients on weak networks read slowly. What happens to the gateway, and what do you do?"

Then they ask

  1. Why not add memory, or slow the whole room down to the pace of the slowest client?
  2. When a buffer is full, which messages do you drop, and which must never vanish silently?
  3. A client that was disconnected for being slow comes back. How should it catch up?

A strong answer covers

  • The gateway keeps copies a client has not taken in that connection's send buffer. A short dip is absorbed and drains.
  • With no limit, a few clients that stay slow collect a growing backlog until the gateway's memory climbs and the process is killed.
  • That disconnects every client on the gateway, including the ones that were keeping up.
  • Cap each connection's buffer, and drop or merge messages that lose their value quickly, such as typing and presence.
  • If the client is still behind, close its connection. When it returns it fetches the current state, not every message it missed.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last reviewed: Official documentation

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.