Guide

WebSocket reconnect best practices

Long-lived sockets face jitter and restarts. Detection, backoff, and state recovery decide terminal stability.

Detect disconnects

Combine server ping/pong with client read timeouts; close past threshold, enter a reconnect state machine, and tag disconnect_reason.

Exponential backoff

Backoff from 1s to a 30–60s cap with jitter. Alert on repeated failures—never spin forever.

Recover state

On reconnect, resubscribe the full set and REST-calibrate last price to fill gaps.

Observability

Track uptime, reconnects, message gaps, and errors. Keep the last subscription list for failover.

References

See /guides/websocket-live-quotes, the Node.js guide, and /tools/ws-debugger.