I built a firehose and called it a live update stream
I want to walk through a design mistake I made in our live-update layer, because it’s the kind of mistake that looks fine on the day you ship it and only shows its real shape once the system grows around it. Nothing is on fire yet. That’s exactly why I want to write it down now, while it’s still a design problem and not an incident.
What I built
Our interface gets its live updates from a single server-sent-events stream. When I wrote the server side, I made the simplest possible choice: every event of every kind goes to every open stream, with one narrow exception for events addressed to a specific device. There is no subscription. A client can’t say “I only care about these kinds” or “only this project.” A stream carries what it carries, and the only way to change that is to close it and open a new one — which also replays the buffer from the last id the client saw.
Then, on the client side, I made a second choice that compounded the first. Our desktop and mobile apps need to raise system notifications even when the webview is backgrounded, so I had the app’s native process follow the stream. The webview also needed the events to keep its store current, so I had it follow the stream too. Two followers per window, each receiving the full, unfiltered feed.
And here’s the part I’m least proud of: I didn’t stumble into this. I wrote both followers into the architecture documentation deliberately, with a rationale. The server module docs say, in so many words, that every event goes to every stream. There’s no requirement anywhere stating what a stream should carry, that a follower subscribes to anything, or that one application instance should hold exactly one connection. I documented the absence of a design as if it were a design.
Why it’s a problem
On a quiet system with a couple of views, none of this matters. But I went back through a recent day’s ingress log for a single desktop window and found it reopened its stream eleven times in twelve minutes, with connections lasting anywhere from a few seconds to a few minutes. Every reopen replays the buffer. Every window does this twice. And every one of those streams carries the entire fleet’s change rate — scheduler events, task changes, notes, graph memory, runs, sprints, instances, across every project — regardless of whether the window is drawing any of it.
We’re actively moving more of the interface’s readings onto this stream. That’s the right direction. But it means an unfiltered stream is going to carry more and more traffic that most windows throw away, and the server’s fan-out cost scales with windows times two times the whole fleet’s activity. The cost I deferred by not building subscriptions is coming due with interest.
The subtler cost is that I’ve made adaptive behavior impossible. A window should be able to narrow its interest when a screen closes and widen it when one opens. Right now the only tool for that is a reconnect-and-replay, which is the worst possible primitive for a “small adjustment.”
What I should have done
Three things, and I can see all of them clearly in hindsight:
One application instance, one stream. The native process should own the connection and hand each event to the webview. The webview shouldn’t open anything of its own. A plain browser window of the web interface holds one connection. The goal I was protecting — notifications still fire when the webview is in the background — is fully served by this arrangement. I just didn’t stop to ask whether two followers were necessary or merely easy.
Streams get an identity and a subscription. The server should assign each stream an id when it’s opened, and the client should subscribe that stream to specific event kinds and scopes — a project, a machine — through ordinary requests that name the stream. The server sends only what’s subscribed. Changing the subscription takes effect on the open connection, with no close, no reopen, no replay.
Subscription is driven by what the window is drawing. We already have a registry that tracks which readings each screen needs so the store can keep them current. That same registry should drive the subscription: a screen registering a reading that’s kept live from events subscribes the kinds that feed it, and the last screen to release that reading unsubscribes them. Interest in data and interest in events are the same thing; I built them as if they were unrelated.
What I’m taking from this
The real failure wasn’t the fan-out logic. It was that I wrote “every event to every stream” into the server docs, wrote “two followers per window” into the architecture, and at no point treated either sentence as a claim that needed defending. If a design document describes behavior without describing a constraint — what should this carry, how many of these should exist — that’s a signal that I haven’t actually designed it yet.
Going forward, when I document a transport or a connection, I’m going to force myself to answer: What does this carry, and who decided? How many of these exist per client, and why that number? How does it change without being torn down? If I can’t answer those, the design isn’t done, no matter how clean the implementation looks.
The fix is a real piece of work — server-side subscription state, a client-side bridge from the native process into the webview, and wiring the reading registry to the subscription. I’d rather do it now than after the stream becomes load-bearing for every screen we have.