I made polling the default, and it locked an operator out of their terminals
Last week an operator spent about ten minutes unable to open any of the terminal sessions in one window of our desktop app. The interface reported the terminals as disconnected. The window had nothing open but terminal tabs. The cause was a design rule I wrote, which the implementation followed faithfully, and which was wrong.
What the window was doing
While the operator was staring at disconnected terminals, that one window was making roughly 300 requests a minute to the controller. About half of those were for readings no view on screen was drawing: the list of machines, the list of projects, open alerts, running operations, fleet power and resource figures, devices, credentials, workspaces, and so on. Each was being re-read every five seconds, our default interval, for the whole life of the window, regardless of what the screen showed.
The controller answers reads from a small pool of database connections on a modest node it shares with its database. Over the incident window it logged more than nine hundred warnings about waiting two to three seconds just to acquire a connection. The agent socket’s frames go through the same store, so the agent’s replies queued behind the starved pool, and four terminal opens hit the thirty-second command timeout and came back as 502s.
None of the readings that caused this changed meaningfully during those ten minutes. We were spending the controller’s capacity confirming, twelve times a minute, that nothing had happened.
The rule I wrote
Our interface conventions have a section on freshness. I wrote it, and the key sentence read, in effect:
While connected, every reading a view draws is kept current: updated from the controller’s events where the controller reports its changes, and read again at an interval otherwise.
That sounds reasonable. It is not. The word “otherwise” made polling the default for every reading the controller did not yet stream, which at the time was most of them. I then compounded it in the same document by defining “launch” and “common” tiers of data that should be fetched “before the operator reaches for it”, and the implementation did the obvious thing with those two statements together: fetch all of it at launch, and keep fetching all of it every five seconds, in every window, forever.
I never wrote down the thing I actually believed, which is that polling is a defect unless the controller genuinely cannot know about a change when it happens. Because I didn’t write it, the code didn’t do it.
Why it was worse than it looked
Three things made this bad rather than merely wasteful:
- The cadence is per window, not per operator. Every additional window adds the full load again. An operator with three windows open on two devices is six copies of the same polling loop.
- The polled set was independent of the screen. “Common” tier meant “always”, so a window showing nothing but terminals paid for the dashboard’s data anyway.
- The cost landed on a shared resource. The reader pool serves the agent socket and terminal commands too. Starving it with cheap, useless reads starved the things the operator actually needed.
There is also a quieter cost: every one of those responses was parsed on the webview’s main thread, right next to the terminals the operator was trying to use.
What I should have written
The controller records every one of these changes itself. It knows when a machine, workspace, project, live session, permission request, or device changes, because it is the one writing that change. It already emits events for some resources (pull requests, alerts, operations, notes, ended sessions). There was no reason it couldn’t emit them for the rest.
So the rule should have been:
- The controller emits an event for every change it records. If the controller wrote it, the controller can announce it.
- The launch and common tiers are read once, at launch, and then kept current from the event stream. They are re-read only when the stream reconnects after a gap during which events may have been missed. They are never read on a timer.
- A reading is polled only where the controller genuinely cannot know of a change as it happens, and that case has to be justified where it is introduced.
- A reading that no visible view draws is never polled, no matter what tier it belongs to.
That is a stricter rule, and it would have forced the right conversation at design time: “which of these can the controller not announce?” The honest answer was “almost none of them”, and the polling would never have shipped.
What I’m changing
- Rewriting the freshness convention so that streaming is the default and polling is the documented exception, with the test above.
- Adding events for the resources that are still polled, starting with the ones a bare window fetches.
- Removing the interval from the launch and common tiers entirely once those events exist, rather than just lengthening it.
- Adding a check in the client that fails if a screen is subscribed to a reading it does not draw, so this cannot regress silently.
- Load-testing with several windows open on one device, since the per-window cost was obvious the moment anyone looked at the access log and nobody had.
We already had a change in flight that bounds polling and pauses it in hidden tabs. It would have softened this, but it leaves the two heaviest tiers on their interval, so it would not have prevented it. The fix is not a better poller; it is not polling.
The lesson
The design document is the place where defaults get set, and a default written as an afterthought (“otherwise, poll”) becomes the behaviour of the whole system. I should have stated the principle I was actually operating under, not a convenient fallback that happened to be easy to implement. When the easy fallback is the one you’d call a defect if someone else wrote it, say so in the design, and make them justify it.