Skip to content
Daksh Garg
All projects

Independent systems project

Low-Latency Order Book & Matching Engine

A C++20 limit order book with price-time priority, O(1) cancel and no heap allocation on the hot path — about 16 million mixed operations per second.

Period
2026
Team
Solo project
Categories
Software Engineering · Backend

Key results

mixed ops / second
16.4Mmixed ops / second1M-op synthetic flow, GitHub Actions runner
p50 limit-order latency
111 nsp50 limit-order latencyp99 351 ns, same run
add + cancel
54 nsadd + cancelGoogle Benchmark, empty book
hot-path allocations
0hot-path allocationsall memory reserved up front

My contribution

  • Designed and implemented the engine, data structures, test suite, benchmarks, latency harness and CI on my own.

Problem

Exchanges and trading firms match buy and sell orders in a limit order book. The interesting engineering is doing it correctly — strict price-time priority, partial fills, IOC/FOK and modify rules — while keeping every operation in the tens-to-hundreds of nanoseconds.

Design

  • Prices as int64 ticks; each side is a flat array of price levels indexed by price, so finding a level is a subtraction.
  • Orders at a level form an intrusive doubly-linked FIFO: O(1) append and O(1) unlink from anywhere.
  • Open-addressing id map (linear probing, Fibonacci hashing, backward-shift deletion) for O(1) cancel and modify.
  • Preallocated object pool and cached best bid/ask with sentinels — no allocator calls after construction.

Testing

GoogleTest covers matching edge cases and every reject path, and each test re-validates every link and cached total in the book. A randomised differential test runs 100,000 operations through both the engine and a simple std::map reference book and requires identical trades and depth. CI also runs the suite under AddressSanitizer and UndefinedBehaviorSanitizer.

Results

On a GitHub Actions runner (AMD EPYC 7763, GCC 15, -O3) a 1M-operation mixed flow ran at 16.4M ops/s, with limit-order latency of 111 ns at p50 and 351 ns at p99. Shared runners are noisy, so the README reports these as orders of magnitude and links the exact CI run.

Next steps

  • Lock-free single-producer/single-consumer queue between a gateway thread and the matching thread, each pinned to its own core.
  • Bitmap of non-empty price levels to make the best-price search O(1) amortised in sparse books.