When we say "sub-second latency," we mean it. Metrics collected by the agent appear in the dashboard in under 1 second, consistently, even when the agent is in Singapore and the dashboard is viewed in New York. Here's how.
Why WebSockets
HTTP polling is the naive approach — agent POSTs metrics every N seconds, backend stores them, dashboard polls the backend. Minimum latency is one polling interval plus round-trip time plus processing time. Even at 1-second intervals, observed latency is 2–4 seconds.
WebSockets solve this with a persistent, bidirectional connection. The agent establishes a connection at startup and keeps it open. When metrics are collected, they're pushed immediately — no new TCP handshakes, no new TLS negotiations. The overhead per metric message is just the JSON payload: 200–800 bytes.
The Agent Collection Loop
The agent runs a tight loop: collect metrics → encode to compact JSON → push over WebSocket → sleep 250ms → repeat. This gives 4 metric snapshots per second per agent. We batch in the backend and emit dashboard updates at 1-second intervals to avoid overwhelming browser clients.
Handling Disconnections
WebSocket connections drop. The agent uses exponential backoff for reconnection — starting at 1 second, doubling to a maximum of 60 seconds. During disconnection, metrics buffer in memory (up to 5 minutes). On reconnection, buffered metrics are flushed before the live stream resumes, ensuring no data gaps in dashboards.
The Actual Numbers
Across 50 globally distributed agents, P95 metric delivery latency is 340ms. Worst outlier across international routes: 820ms — still under 1 second. For most server/dashboard combinations, latency is under 200ms.