Snapshot + subscribe
Don’t rely on the live feed alone to build initial state. Subscribe first, then seed from REST inside thesubscribed handler. This closes the gap between “when you fetched the snapshot” and “when your first publication arrives”:
- Create a subscription with
positioned: true, recoverable: true - In the
subscribedhandler, fetch current state from REST - Apply live updates as publications arrive
subscribed handler fires — check wasRecovering and recovered to decide whether you need to re-seed (see Recovery).
Recovery flags
Pass both flags together on channels with history enabled:positioned bookmarks your place in the stream. recoverable uses that bookmark to replay missed messages on reconnect. Either flag alone does nothing useful — you need both. For channels without history (best_odds, parlay_markets), omit both and re-seed from REST on every reconnect.
See Namespace history capabilities for which channels support recovery.
Recovery
After a reconnect, thesubscribed event tells you whether your local state is still consistent:
wasRecovering | recovered | What happened | Action |
|---|---|---|---|
true | true | History replay filled the gap | Nothing — state is consistent |
true | false | History window expired before reconnect | Re-seed from REST |
false | — | Fresh connect | Seed from REST |
recovered will be false and you must re-seed.
Deduplication
At-least-once delivery means a message can be replayed more than once during recovery. Every publication includes amessageId in ctx.tags — track seen IDs and skip duplicates:
512 channel limit
Each connection supports a maximum of 512 simultaneous subscriptions. If you exceed this, the subscribe call returns error code106. Create additional client instances for additional channels — each gets its own connection and its own 512-slot budget.
Slow consumer
The server buffers up to 1 MB per connection. If yourpublication handler is slow, the buffer fills faster than it drains and the server closes the connection. Hand off incoming messages to a queue immediately — do not do heavy work inline. Unexpected disconnects that aren’t auth errors are often a saturated buffer.
Real-time Data →
Full code examples for all patterns above, plus common failures and error codes.
