(Note · · 5 min read)

You probably do not need websockets for that

A dashboard needs live numbers, so the plan becomes websockets. That brings reconnection logic, a server that must hold connections, state that diverges when a message is missed, and a scaling model that no longer fits behind an ordinary load balancer — frequently to update figures that change every few seconds.

By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka

Ask how fresh the data must be

There is a real difference between a trading view where a second matters, an operational dashboard where a few seconds is fine, and a report somebody reads for a minute. Only the first needs a push.

On the trading-bot dashboards I led the frontends for, the figures move constantly and are fetched on an interval with a query library managing caching, deduplication and refetching. The user's experience is of live data; the transport is ordinary requests.

Polling done well is unobtrusive

What makes polling feel bad is doing it naively. Done properly it is hard to distinguish from a push, and it keeps the server stateless.

  • Stop polling when the tab is hidden, and refetch once on return.
  • Deduplicate: several components wanting the same data make one request.
  • Keep showing the previous value while refetching, so nothing flickers.
  • Return a not-modified response when nothing changed, so an unchanged poll is cheap.
  • Back off when the user is idle or the window has been in the background a while.

That last point matters for cost. A dashboard left open on fifty desks polling every second is fifty requests a second for figures nobody is looking at.

Send changes, not the whole state

Where a payload is large, poll with a cursor — give me what changed since this point — and apply the changes locally. That keeps responses small without a persistent connection.

It also makes reconnection trivial: having a position, a client that was away simply asks for what it missed. That is the hardest part of a push-based system, and here it is free.

When you do need a push

Genuine cases exist: collaborative editing, chat, anything where latency is the product, and server-driven events that cannot be anticipated. For one-directional updates, server-sent events are much simpler than a full duplex connection and run over ordinary HTTP.

If you do take a persistent connection, plan for what it demands: reconnection with backoff, resuming from a position rather than from nothing, heartbeats to detect a connection that is open but dead, and a message broker once there is more than one server instance.

The hybrid is often best

Fetch the state normally and use a lightweight signal only to say that something changed. The client then refetches through the same path as the initial load — one code path for reading data, and no divergence between the pushed state and the fetched state.

That divergence is the subtle cost of push-everything architectures: two ways for the client to learn the same fact, and bugs that only appear when one of them is missed.

Make the staleness visible

Whatever the transport, show when the data was last updated and say clearly when the connection is lost. A dashboard displaying a stale number as though it were current is how someone makes a decision on figures from twenty minutes ago.

Common questions

Do I need websockets for a live dashboard?

Usually not. A persistent connection brings reconnection logic, stateful servers, divergent client state and a harder scaling model. Polling with a query library that handles caching, deduplication and refetching reads as live to users while keeping the server stateless.

How do I make polling efficient?

Stop when the tab is hidden and refetch on return, deduplicate requests across components, keep showing the previous value while refetching, return not-modified when nothing changed, and back off when the user is idle.

How can polling send only changes?

Poll with a cursor — what changed since this point — and apply updates locally. It keeps payloads small, and makes reconnection trivial, since a client that was away just asks for what it missed. That is the hardest part of a push system and here it is free.

When is a persistent connection justified?

Collaborative editing, chat, anything where latency is the product, and unanticipated server-driven events. For one-directional updates server-sent events are far simpler, and a hybrid — a lightweight signal that triggers a normal refetch — avoids having two paths to the same fact.

Need something like this built?