Beyond the efficiency of the network, the primary driver for moving to a push-based system is the need for operational consistency. When every browser independently decides whether a device is present, a single operational fact is divided across many different clocks. In a polling setup, one operator’s tab might have just refreshed, showing an encoder as "offline," while another operator’s tab is still four seconds away from its next poll, showing the device as "online."
This disagreement between screens is more than a nuisance; it is a liability when an operator must decide in a split second whether an encoder is ready for a live broadcast. To eliminate this, the presence of a device should be defined on the server using the latest accepted signal and a strict deadline. Under this model, the browser receives an initial snapshot of the entire fleet upon connection, followed by a stream of revisions. The browser then accepts only newer events, ensuring that an old update cannot overwrite fresh data.
There is, however, a meaningful trade-off in how these deadlines are set. A long deadline—the time the server waits before declaring a silent device "offline"—can hide a genuine failure for too long. A deadline that is too short can turn a brief, harmless network hiccup into "flapping," where devices appear to toggle rapidly between online and offline states. The ideal deadline should be derived from the device’s heartbeat contract and a clear understanding of the consequences of a false positive versus a false negative.
By centralizing this logic, the failure states become explicit. In a well-designed system, "offline" means the presence deadline has elapsed, while "unknown" means the dashboard has lost its connection to the server and cannot confirm the current state. Combining these into a single "offline" indicator is a "clean-looking lie" that can mislead operators during a system-wide outage.
The Smallest Node.js Implementation
Implementing a push-based system does not necessarily require a heavy commercial service. A single-process Node.js example can expose the underlying state machine. In such a system, the server maintains an authoritative map of devices and a set of connected viewers. When a device sends a heartbeat, the server updates its map, increments a revision number, and publishes the change to all connected viewers using Server-Sent Events (SSE).
In this architectural pattern, the server handles the "expiry" of devices. A background interval checks the "last seen" timestamp of every device; if the time elapsed exceeds the predefined timeout, the server marks the device as offline and pushes that update to the dashboards. This ensures that the logic for "what constitutes being online" lives in exactly one place.
The client-side logic in this scenario remains remarkably simple. The browser maintains its own map of the fleet. When it receives a presence event, it compares the revision number of the incoming data with the revision of the data it currently holds. If the new revision is higher, it updates the display. This "boring" approach is highly effective because it prevents out-of-order messages—common in distributed networks—from causing the dashboard to display stale information.
