Heartbeat
Send a ping every 30 seconds to keep the connection alive:Reconnection strategy
Network disruptions are inevitable. Your client should handle disconnections gracefully with exponential backoff:- On disconnect, wait a short initial delay (e.g., 1 second).
- On each failed reconnection attempt, double the delay up to a maximum (e.g., 30 seconds).
- Add random jitter to prevent thundering herd when many clients reconnect simultaneously.
- After reconnecting, re-authenticate and re-subscribe to all channels on that connection.
Best practices
- One connection per endpoint family — share one
bookconnection for orderbook channels and onenonbookconnection for everything else, rather than opening one connection per subscription. - Subscribe in batches — send all channels in a single
public/subscribemessage rather than one message per channel. - Handle backpressure — keep your message handler lightweight. Offload heavy processing (database writes, analytics) to a background queue.
- Track subscriptions client-side — maintain a local registry of active subscriptions so you can re-subscribe after reconnection.
- Use compression — enable
brotlicompression to reduce bandwidth, especially for high-frequency channels likeTRADEandBLOCK_BOOK_SNAPSHOT.