# Consistency Guarantees

## Market data streaming

When streaming market data via a websocket topic, the following guarantees are provided:

**Snapshots**:

When subscribing to a market data topic, the first message received will be a snapshot of the current state of the order
book.

This can be recognized by the `mt` field which will be set to `"s"` (snapshot). Subsequent messages will have `mt` set
to `"u"` (update).

**Backend disconnections**:

If the backend experiences connectivity issues with the exchange rollup/matching engine, on recovery a snapshot will be
sent to ensure the client has a consistent view of the order book.

**Ordering**

Depth updates are published with sequence identifiers, which allows clients to detect if any updates were missed.

- `u` -> 'last update id' - a monotonic sequence number incremented with each new update.
- `pu` -> 'previous update id' - the `u` value from the previous message. On the first snapshot, `pu` is `0`.

By comparing the `pu` of the current message with the `u` of the last received message, clients can determine if any
updates were missed. If there is a gap in the sequence, unsubscribe and resubscribe to get a fresh snapshot of the order
book to ensure consistency.

**Periodic snapshots**:

In addition to the initial snapshot, the server periodically sends full snapshots (approximately every few seconds). This
acts as a self-healing mechanism — even if a client misses a delta update, the next periodic snapshot will bring its
local state back in sync without needing to resubscribe.

Any message with `"mt":"s"` is a full snapshot and should replace the client's local state entirely. Snapshots are sent
on initial subscription, periodically, and on recovery from backend connectivity issues. After a snapshot, sequence
numbering may reset — clients should not validate `pu` continuity across snapshots.
