Jack Jiang

Systems

Low-Latency Order Book and Matching Engine

A C++ matching engine that maintains bid and ask books and processes add, cancel, modify, and execute events using price-time priority.

In progressPersonal project2025
  • C++
  • Linux
  • CMake
  • GoogleTest

Problem

A matching engine has to maintain strict price-time priority ordering while supporting fast order lookup, cancellation, and modification — data-structure choices here directly determine throughput and tail latency.

Constraints

  • Cancellation and modification must locate the target order in the book quickly, not via a linear scan
  • Price levels must stay ordered without expensive re-sorting on every event
  • Partial fills need to update book state without violating price-time priority

Approach

Maintains ordered price levels with per-level order queues so price-time priority falls out of the data structure directly, paired with an index for O(1) order lookup so cancel/modify paths don't require scanning the book.

System design

Matching-engine event-processing architecture

Incoming events are routed by type; the book maintains ordered price levels for matching while an order index supports fast cancel/modify lookups.

  1. Incoming event (add / cancel / modify / execute)
  2. Order index lookup (for cancel / modify)
  3. Ordered price-level book (bids / asks)
  4. Price-time priority matching
  5. Fill / partial-fill generation
  6. Book state update

Tradeoffs and limitations

Optimizing for fast cancellation (via an auxiliary index) adds bookkeeping overhead on every add/execute event — the design accepts that cost because cancellation is the hottest path in practice.

Results

This project is still in progress. The intended benchmark is sustained throughput and tail latency under a synthetic event stream (add/cancel/modify/execute mix), profiled to find the dominant cost paths. No throughput numbers are published yet — they will be added once measured and verified.

Next steps

Finish the profiling harness, measure throughput/latency under realistic event mixes, and use the profiling results to guide further optimization before publishing benchmark numbers.

All projects