Summary

A limit order book (LOB) maintains sorted lists of buy (bid) and sell (ask) orders at each price level. The matching engine processes incoming orders against the book, generating trades when bid >= ask. Design choices at every layer (data structure, memory layout, cancellation strategy) compound into the final throughput and latency profile.

Design Dimensions

DecisionOptionsTrade-off
Price level storagestd::map vs flat arrayTree = O(log n) + cache misses; Array = O(1) + cache-friendly
Order queuestd::deque vs intrusive listDeque = O(n) cancel; Intrusive = O(1) cancel
Trade reportingReturn vector vs template callbackVector = heap alloc per call; Callback = zero alloc
Price representationdouble vs integer ticksFloat = non-deterministic equality; Ticks = exact

Architecture Comparison

See hft-matching-engine for the three-iteration build log with measured throughput and latency at each stage (823K to 2.72M ops/sec).