When should a market data service switch back to WebSocket after using snapshots?

TickDB Research ·

When should a market data service switch back to WebSocket after using snapshots?

A market dashboard can move backward in time if it returns to streaming on the first message after an outage. We replayed historical Cambricon prices with injected failures to compare two switchback rules and provide an acceptance check for on-call engineers.

Your dashboard uses snapshots during a streaming outage. The stream reconnects and delivers a first update stamped 10:04. The display already shows a snapshot stamped 10:06. Switching back immediately would show an older update and could feed a discontinuity into an alert rule. The on-call decision is when to change the display source and when to resume alerts that require continuous data.

Check business data after the connection recovers

TickDB WebSocket supplies streaming updates. REST snapshots can refresh the latest observed state during a gap. Keep source timestamps for both. Before switching back, check that the subscription is delivering valid messages for the intended symbol, then compare their source time with the displayed value. Heartbeats, subscription confirmations and unrelated symbols do not count. Check quote age separately to catch streams that advance but are still too far behind. TickDB Stock Market Data API

Replay the same events with two rules

This offline replay uses closing values of one-minute Cambricon 688256.SH bars from November 12, 2026. We injected the arrival order and failures to produce a delayed message, a second outage and sustained recovery. Times below are historical bar labels. The replay does not use the production WebSocket or measure network latency. [1–2]

Injected sequenceSwitch back on the first primary messageReject old messages and require three increasing source times
Primary goes down, snapshot advances to 10:06Display snapshotDisplay snapshot
First primary message arrives with label 10:04Switch back and display 10:04Reject older message and keep snapshot
Primary drops again, snapshot advances to 10:07Fall back againKeep snapshot
Primary delivers 10:08, 10:09 and 10:10Switch back at 10:08Switch back at 10:10 and ignore the repeated 10:10

With the same offline inputs the switchback rules caused four vs two transitions and one vs zero time regressions

The first drop counts as a transition in both cases. The immediate rule made four transitions and one source-time regression. The stability rule made two transitions and no source-time regressions. With the replay cut off after 10:09, two valid messages were insufficient to switch back. The comparison changes both timestamp validation and the message count. The result applies to the combined policy. In the replay, an advancing snapshot, another outage or a rejected candidate resets the count. Three is a test threshold. Set it for your feed cadence, sessions and tolerance for delay.

Give the on-call team an acceptance check

For each symbol, log the displayed source time, candidate timestamp, valid streak, current state and alert eligibility. During fallback, show the snapshot time and pause alerts that depend on continuous updates. Count a business message only when its source time is later than both the displayed value and the preceding candidate. This example isolates the ordering check.

def may_count(source_minute, displayed, last_candidate):
    return source_minute > displayed and (
        last_candidate is None or source_minute > last_candidate
    )

shown = "10:06"
print(may_count("10:04", shown, None))
print(may_count("10:08", shown, None))
print(may_count("10:08", shown, "10:08"))
False
True
False

These comparisons use bar labels for one day and symbol. Use comparable full timestamps in production. Exercise the stale-message, stable-recovery and prolonged-silence branches. If a snapshot is absent or too old, display unavailable. After switching sources, rebuild or backfill any window needed by continuous alerts before re-enabling those alerts.

Frequently asked questions

What if the price has not changed? Use the business message's source time and the instrument's trading status. An unchanged price alone cannot diagnose a connection.

Does switching back recover all missed messages? The replay verifies switchback behavior and display time. Test historical recovery, gaps and recalculation separately for tasks that depend on a complete window.

References

  1. TickDB Docs, WebSocket quickstart and market snapshot fields.
  2. TickDB historical sample, 688256.SH, November 12, 2026, 10:03–10:11 Shanghai time, unadjusted one-minute bars. Failures, snapshot delivery and arrival order were injected locally.

This week’s offer

Official TickDB Black Friday subscription week banner

November 23–29, 2026, through 23:59 Beijing time. Save 15% on six months and get an extra half month, or save 20% on a year and get an extra month. Eligible for new paid subscriptions and renewals.

7 markets · 43,111 symbols

US stocks
14,809
Hong Kong market
3,354
China stocks, ETFs & bonds
7,576
Forex & metals
1,228
Indices
13,960
Futures
1,172
Crypto
1,012
11/27/2026

Explore related data tools

Related articles

Choose a Stock API by Testing Disconnect Recovery, Not Just Streaming Speed

A stock API can reconnect quickly while leaving an application with incomplete subscriptions or an unexplained gap in event history. Choose it by testing when data becomes usable again, not merely when the socket opens. A fresh snapshot can restore current state; only a documented replay or backfill mechanism can establish the required event continuity. The acceptance test below separates those outcomes and includes a small, locally tested recovery gate.

TickDB Research ·

Choose a US Stocks API That Keeps Extended Hours Data Distinct

A US stocks API can return a valid price while leaving an extended-hours screen misleading. For a product that shows pre-market, post-market or overnight activity, choose a feed whose coverage and session semantics you can verify, then keep each observation tied to its session and timestamp. TickDB documents separate extended-session snapshot objects; Alpaca documents separate stock feeds. Those are different integration choices, and neither removes the need to test missing data and session transitions.

TickDB Research ·

Choose a Stock API by Testing Requirements Before Comparing Price

A stock API can return valid JSON and still be unsuitable for your application. Choose candidates that meet your required data coverage, permitted use and operating capacity, then compare their total cost under the same workload. Alpaca’s documented IEX and SIP feed distinction shows why matching ticker symbols is not enough. A small acceptance test, with unresolved requirements kept visible, produces a more defensible shortlist than a feature count.

TickDB Research ·

Stock API Watchlists Can Share Requests Without Hiding Stale Prices

A stock watchlist can exhaust an API budget even when every user follows the same symbols. Where data permissions allow it, batching those symbols and sharing retrieval across viewers reduces duplicate upstream requests while preserving each record's timestamp. In a hypothetical case with 20 identical 120-symbol watchlists, batches of 50, and a five-second polling interval, independent polling needs 720 requests per minute; one shared collector needs 36, before retries and other traffic.

TickDB Research ·