| Choice | Idle work | Reconnect behavior | Best fit |
|---|---|---|---|
| Fixed-interval polling | One read per viewer per interval | Next read restores the view | Small, low-urgency screens |
| Push plus cursor backfill | One open channel per viewer | Resume after the last applied event | Live operations dashboards |
Short answer: for a live shipment dashboard with more than a few simultaneous viewers, use push for new notifications and a cursor-based read for reconnects. Polling repeats reads even when no shipment changes. Push moves work toward actual changes, but it wins only if reconnect and backfill are designed as one protocol.
That last clause matters. An open connection is not a durability mechanism. A browser sleeps, a train enters a tunnel, or a deploy closes a process. The dashboard still has to recover every committed shipment update without duplicating visible notifications.
Why does pushing beat polling above a handful of viewers?
Polling cost follows a blunt equation:
reads = viewers x polls per viewer
With 12 dispatchers polling every 5 seconds, the system handles 144 reads per minute even when nothing changes. That number is arithmetic, not a benchmark or a vendor price. Add another viewer and the background read rate rises again. Shorten the interval and it rises in direct proportion.
Push has a different shape. It keeps one channel per active viewer, then sends data when a shipment event exists. A status change still fans out to every interested dashboard, so push does not make delivery free. It removes the repeated application reads between changes. That is why pushing beats polling on idle work above a handful of viewers; the cost shift is explained by request frequency, not magic in the transport.
This is the useful decision rule: compare idle reads with event fan-out, then include reconnect traffic. If dashboards are open all day while shipment changes are intermittent, repeated reads dominate early. If every dashboard sees a firehose of changes, fan-out, serialization, and client rendering become the larger costs. Measure both paths with the same payload and the same viewer count. Vague "real-time" benchmarks are noise.
I would record four counters: active connections, committed events, delivered messages, and backfilled events. Those numbers expose the actual multiplier. They also keep infrastructure pricing out of the architecture decision; unit prices change, while the workload shape does not.
Reconnect is the real protocol
The server needs a stable ordering token. Call it a cursor. Every committed shipment event receives one, and the browser stores the latest cursor only after it has applied that event. On reconnect, the client asks for events after that cursor before treating the live stream as current.
Order the transition carefully:
- Open the live channel and temporarily buffer incoming events.
- Read committed events after the stored cursor.
- Apply the backfill in cursor order.
- Apply buffered live events, ignoring cursors already seen.
- Continue with the live channel.
Without the buffer, an event can land between the backfill query and live subscription. Without deduplication, overlap between those paths can show the same "arrived at hub" notification twice. Exactly-once transport is not required here. An ordered cursor plus idempotent application is enough.
Keep retention explicit. A cursor older than the retained event log cannot be resumed honestly. Return a reset signal, fetch a fresh shipment snapshot, and start from that snapshot's cursor. Silent gaps are worse than a deliberate reset.
A small TypeScript boundary
The transport should be boring. Put recovery semantics behind one interface so the dashboard does not care whether live delivery uses a browser event stream, a bidirectional channel, or another standards-based mechanism.
type ShipmentEvent = {
cursor: number;
shipmentId: string;
status: "picked_up" | "at_hub" | "out_for_delivery" | "delivered";
occurredAt: string;
};
type RealtimeSource = {
connect(onEvent: (event: ShipmentEvent) => void): () => void;
backfill(afterCursor: number): Promise<ShipmentEvent[]>;
};
export function followShipments(
source: RealtimeSource,
initialCursor: number,
apply: (event: ShipmentEvent) => void,
): () => void {
let cursor = initialCursor;
let recovering = true;
const buffered: ShipmentEvent[] = [];
const accept = (event: ShipmentEvent) => {
if (event.cursor <= cursor) return;
apply(event);
cursor = event.cursor;
};
const disconnect = source.connect((event) => {
if (recovering) buffered.push(event);
else accept(event);
});
void source.backfill(cursor).then((missed) => {
for (const event of [...missed, ...buffered].sort(
(a, b) => a.cursor - b.cursor,
)) {
accept(event);
}
recovering = false;
});
return disconnect;
}
This is intentionally small. Production code also needs cancellation, authentication refresh, a defined reset response for expired cursors, and bounded buffering. Those are protocol requirements, not configuration decorations. Each knob should correspond to a failure you can name.
The server must assign the cursor when the event becomes committed, not when a socket happens to send it. Otherwise two processes can disagree about order. Persist first, publish second. Then test a disconnect at every transition: before commit, after commit but before delivery, during backfill, and while buffered events are draining.
What should you measure before rollout?
Start with time-to-first-current-state. A fast connection that spends seconds replaying old events is still a slow dashboard. Track backfill size and age, reconnect attempts, reset frequency, delivery lag, duplicate events discarded, and buffer depth. Alert on sustained lag and repeated resets rather than raw connection count alone.
Benchmark the boring case.
Run idle dashboards for the length of a normal shift, because that is where polling performs needless work. Then replay a realistic burst, sever connections, and verify that every client converges on the same cursor. The acceptance check is a state invariant: after recovery, the dashboard matches the committed shipment state and has no duplicate user-visible notification.
Deployment needs the same skepticism. Drain connections during a release, allow clients to reconnect with jitter, and keep the backfill store available independently of any single connection handler. A reconnect wave should increase backfill work predictably rather than turn into synchronized retry traffic.
When is polling the better runner-up?
The main limitation of push is operational: open connections, draining, retention, and recovery all need ownership. That trade-off is wrong when the screen is opened briefly, updates can be several intervals late, and a normal snapshot read is cheap. Polling is also easier when intermediaries cannot hold long-lived connections or the team cannot yet operate connection draining and cursor retention. For two dispatchers checking a low-volume depot every few minutes, the extra protocol may buy little.
There is a middle ground: poll with a cursor and return only changes. That keeps recovery semantics while avoiding an open channel. It still performs idle requests, but migration to push later becomes smaller because ordering, deduplication, and retention already exist.
WebRTC is another transport option, standardized for real-time peer communication. It brings peer connection, media, and data-channel machinery that a server-owned shipment notification feed may not need. Choose it when peer-to-peer communication is itself a requirement, not because "real-time" appears in the project brief.
The architecture decision is therefore narrow: choose the least complex transport that meets update latency, then refuse to ship it until cursor recovery passes the disconnect tests. For an all-day logistics dashboard, push plus backfill usually fits the workload. Polling remains the cleaner answer for sparse, delay-tolerant viewing.
Further reading
- W3C, WebRTC 1.0: Real-Time Communication Between Browsers: https://www.w3.org/TR/webrtc/
Top comments (0)