feat: single monotonic order-book version chained across snapshots and deltas#71
Merged
Merged
Conversation
…d deltas Adds the market-data ordering primitive the book stream was missing: one version per BOOK (not per side), stamped from the Aeron log position, chaining snapshots and deltas so any client can join mid-stream and converge on the identical book. - Engine: each mutating command stamps the market's bookVersion as max(current+1, Header.position()) BEFORE processing — deterministic across replicas (same log) and never regressing across restarts or failovers without touching the engine snapshot format. Both engine impls publish it through their existing seqlock/snapshotLock so the flush thread's collected (arrays, version) pair is consistent. - SBE schema v4 (extension fields, mixed-version safe during a rolling update): BookSnapshot gains bookVersion; BookDelta gains bookVersion + fromVersion — every delta names the published state it extends, so consumers can DETECT gaps despite flush-level coalescing. - MarketPublisher maintains the published chain (fromVersion = last published state's version). - Gateway: decodes with null-guards for pre-v4 upstreams, tracks the chain in GatewayOrderBook (JSON 'bookVersion', with 'version' now the same value), validates continuity (counter + warn; the session-open resnapshot re-establishes after seams), and forwards bookVersion/fromVersion on broadcast deltas. Client protocol this enables (implemented in trading-ui): subscribe to deltas first, buffer; fetch a snapshot (version V); drop buffered deltas with bookVersion <= V; replay the rest verifying each delta's fromVersion continues the chain; on any gap, re-snapshot. All clients see the same book and the same updates. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the ordering primitive the market-data book stream was missing: ONE version per book (not per side), stamped from the Aeron log position, chaining snapshots and deltas so any client can join mid-stream, stitch deterministically, and converge on the identical book.
Design
bookVersion = max(current+1, Header.position())before processing — deterministic across replicas, never regresses across restarts/failovers, and needs no engine-snapshot format change (the first post-restore command jumps to the live log position). Published through the existing seqlock (array engine) / snapshotLock (direct engine) so the flush thread's (arrays, version) pair is consistent.sinceVersion=4extension fields (mixed-version safe during the rolling update):BookSnapshot.bookVersion,BookDelta.bookVersion + fromVersion. Deltas naming the state they extend makes gaps DETECTABLE despite flush-level coalescing.GatewayOrderBook(JSONbookVersion), continuity validated (warn + counter; session-open resnapshot re-establishes after seams), chain fields forwarded on broadcast.Client protocol (trading-ui#35)
Subscribe to deltas first → buffer → snapshot(V) arrives → drop buffered deltas ≤ V → replay the rest, verifying each
fromVersioncontinues the chain → any gap ⇒ automatic re-snapshot. All clients see the same book and the same updates.Verification
bookVersionlive in REST/WS JSON (legacy fallback until the cluster rolls).🤖 Generated with Claude Code