Description: FIFO price-time priority order matching engine in Rust — 10M orders/sec, P99 < 200ns Topics: rust matching-engine low-latency orderbook trading fintech
- To get detail explanation of this Project I published in Medium https://medium.com/@raghavaashok2004/building-a-nanosecond-order-matching-engine-in-rust-4a7456452446
-
order-book/limit-order-no-match:
-
time: [95.543 ns 97.853 ns 100.03 ns]
-
thrpt: [9.9968 Melem/s 10.219 Melem/s 10.466 Melem/s]
-
change:
-
time: [-16.775% -10.863% -4.9920%] (p = 0.00 < 0.05)
-
thrpt: [+5.2543% +12.187% +20.156%]
-
Performance has improved.
-
order-book/limit-order-with-match
-
time: [194.73 ns 195.23 ns 195.71 ns]
-
thrpt: [5.1095 Melem/s 5.1223 Melem/s 5.1352 Melem/s]
-
change:
-
time: [-0.9761% -0.3319% +0.2483%] (p = 0.30 > 0.05)
-
thrpt: [-0.2477% +0.3330% +0.9857%]
-
No change in performance detected.
- BTreeMap price levels — sorted iteration free, no per-tick sort
- SmallVec[Order; 4] — stack allocation for levels with ≤4 orders
- Zero-allocation hot path — fill buffer reused via
std::mem::take - O(1) cancel — secondary index maps OrderId → (Side, Price)
- Integer prices — stored as cents, avoids float comparison bugs
cargo run # correctness demo
cargo bench # benchmark with criterion
cargo flamegraph --bench throughput # perf flamegraphcargo run
# open http://localhost:3000Live WebSocket dashboard showing throughput, P99 latency, and order book snapshot.
- FIX 4.2 protocol parser
- Lock-free SPSC input queue
- Deterministic replay engine over memory-mapped log