ApexBook — Lock-Free Matching Engine
An HFT limit order book in C++20 with ~200ns latency and 100M+ orders/sec throughput.
~200ns
Latency
100M+/s
Throughput
Zero
Allocations
Problem
Traditional order books suffer from lock contention and heap fragmentation, blowing latency budgets during high-frequency trading.
Architecture
MPSC/SPSC ring buffers feed a lock-free matching core. Cache-line-aligned structures prevent false sharing; a custom object pool avoids OS heap allocation entirely.
Challenges
- — Eliminating false sharing on hot paths
- — Achieving deterministic sub-microsecond latency
- — O(1) order cancellation
Engineering Decisions
- — Chose intrusive doubly-linked lists for O(1) cancels
- — Preallocated object pool over malloc/free
Tradeoffs
- — Higher memory footprint for latency guarantees
- — Increased code complexity for lock-free safety
Future Work
- — Multi-symbol sharding
- — NUMA-aware allocation
- — FPGA offload research