Presence: The Green Dot Is the Worst Data in the Product

Why Presence Is Uniquely Awful

ChurnExtremely high — every lid open, lock, idle timeout, and network blip flips a bit
Value per changeAlmost zero — nobody is waiting on a dot
Interest setPotentially everyone, which is what makes the naive design quadratic

Messages have the opposite profile: relatively rare, high value, and a bounded audience (a channel's members). You can afford to work hard per message. You cannot afford to work hard per presence flip, because there are orders of magnitude more of them.

The Naive Design and Its Arithmetic

Broadcast every presence change to every connected client in the workspace. Take a 10,000-user workspace where each person's state flips ~20 times a day:

10,000 users × 20 flips = 200,000 changes/day

200,000 changes × 10,000 recipients = 2,000,000,000 events/day — for one workspace, for a dot

And it is O(N²): doubling the workspace quadruples the traffic. Worse, the recipient throws away essentially all of it — a client showing 30 faces has no use for the other 9,970 updates. You are spending quadratic bandwidth to deliver data that is discarded on arrival.

Slack's Answer: Query + Subscribe, Scoped to the Screen

Slack runs dedicated Presence Servers — in-memory, with users hashed onto individual PS hosts. Clients reach them through their Gateway Server, which proxies presence queries over the existing WebSocket (no second connection).

Slack publishes that shape — users hashed to PS hosts, the GS as proxy, notifications “only for a subset of users that are visible in the app screen at any moment” — but not the wiring, so the following is reasoned from it. A state change originates at the Gateway Server: it is the thing that sees your socket open, sees it drop, and receives your client's “I've gone idle.” It reports that to the one Presence Server that owns your user ID — hash(U123), the same arithmetic as the Gateway and Channel Servers part. The presence_sub list a client sends is per-socket, so the natural place to hold it is the GS — which is exactly why it dies with the socket for free — and the GS then registers with each PS that owns one of the named users, once per user however many of its clients want that user. It is the CS/GS two-level tree again, with the Presence Server in the Channel Server's seat: PS maps a user to the Gateway Servers watching them, GS maps that user to the local sockets. Three mechanisms do the real work:

  1. presence_query — pull, for what you're rendering now. When the client paints a member list or a DM sidebar, it asks for the current presence of exactly those user IDs. One round trip, bounded by what's visible, not by workspace size.

  2. presence_sub — push, but only for a set you named. The client sends the list of users it wants live updates for. Slack then sends presence_change events only for those users. Crucially, the subscription lives exactly as long as the WebSocket. No leases to renew, no TTLs to tune, no orphaned subscriptions to garbage-collect — socket dies, subscription dies, atomically and for free.

  3. batch_presence_aware — coalesce what's left. A client that declares this flag receives batched events carrying a users array instead of one event per user. Fifty people coming online in the morning is one frame, not fifty.

Broadcast versus subscription, drawn as a matched pair: the two panels are geometrically identical — same trigger, same fan-out box, same grid of candidate clients, same arithmetic strip, all at the same positions — so that the only visible difference is which clients receive the event. Left panel, BROADCAST, the naive design: one user flips to away; send to every connected client in the whole workspace; no list is consulted, so nobody can be left out. Below it a grid of one hundred dots, where one dot stands for one hundred connected clients, and every single dot is lit red: the recipient set is all ten thousand of them, and 9,970 of those have this user off screen and discard the event on arrival. The arithmetic: two hundred thousand flips a day times ten thousand recipients equals two billion events a day — order N per flip, order N squared in total, so doubling the workspace quadruples the traffic. Right panel, SUBSCRIPTION, presence_sub scoped to the screen: the identical trigger, one user flips to away; send to every subscribed client that named this user in presence_sub; the list dies with the socket, so there is nothing to expire. Below it the identical grid of one hundred dots, with exactly one dot lit green: the recipient set is the roughly thirty clients with this user on screen, the rest were never in the set at all, and thirty is in fact under a third of one dot at this scale. The arithmetic: two hundred thousand flips a day times about thirty watchers is roughly six million events a day, and the thirty is whatever is on screen — it never grows with N. Same trigger, same machinery, same candidate set of clients; only the recipient set differs, and that one difference is the whole gap between order N squared and a cost bounded by what a human can see.
Broadcast vs. subscription — the recipient set is the whole difference

The Principle Worth Extracting

Scroll a member list and your subscription set changes. The viewport is the subscription. Cost becomes proportional to what a human can actually perceive — a few dozen faces — which is constant no matter how large the company gets.

This is the same move as the Flannel part: Flannel made connect cost proportional to the working set; presence_sub makes presence cost proportional to the visible set. Both replace "everything about the workspace" with "the bit currently in front of a human."

Detecting "Away" Without Being Told

The second half of presence is the state nobody reports. Users close laptops, lose wifi, and walk away; almost none of them log out. So online-ness cannot be a flag someone sets — it has to decay:

  • Connected is directly observable — the Gateway Server either holds your socket or it doesn't. A dropped TCP connection is the offline signal, arriving for free.
  • Active vs. away is the client's judgement: the client watches for input and declares itself away after an idle period, or when the OS reports the screen locked. The server doesn't guess.
  • The fallback is a lease. If a socket dies without a clean close — the common case on mobile networks — the server can't distinguish "gone" from "quiet." State must expire on a heartbeat/TTL basis rather than persist forever, which is why a presence dot occasionally lags reality by tens of seconds.
  • Guarantees: Presence traffic to a client is bounded by what that client asked for, and a subscription can never outlive its connection — the socket's lifetime is the subscription's lifetime, so there is nothing to leak.
  • Does not guarantee: That the dot is correct right now. A user who loses connectivity without a clean disconnect shows as online until their state decays, and with batching, updates arrive in groups rather than instantly.