Market Data Feed is a C++20 feed handler for compact binary market-data messages. It parses the wire format, tracks sequence numbers, recovers from gaps, applies updates to an L2 order book, and replays recorded streams deterministically.
Binary Protocol
Every message opens with a 16-byte little-endian header carrying magic, version, type, sequence, and symbol id, followed by a payload that varies by message type. The set covers add, modify, cancel, trade, snapshot, and heartbeat. Invalid magic, version, type, or length is rejected outright, without mutating the book.
Sequence Tracking and Recovery
A feed handler is judged by how it treats the packets it never received. The sequence tracker drops duplicates, buffers a bounded window of out-of-order messages and flushes them in order, and flags anything past that window as a gap. Gaps trigger snapshot-based recovery instead of leaving the book quietly wrong.
Deterministic Replay
Recorded sessions replay through the same parse path with no wall-clock delays, so book state after a replay matches the state from the original recording exactly. That property is what turns an intermittent bug into a reproducible one.
Hot Path
Parsing and book updates are decoupled across a bounded single-producer single-consumer queue, and orders and buffers come from preallocated pools to keep allocation out of the steady state. In-memory replay on a modern desktop clears a million messages per second, with median parse-to-enqueue latency under a microsecond and high percentiles in the low microseconds.
Testing
GoogleTest suites cover malformed packets, duplicates, missing and out-of-order sequences, snapshot recovery, record and replay identity, the object pools, and the SPSC queue, alongside a Google Benchmark harness for throughput and latency.