Skip to main content

03Systems / Market Microstructure

Low-Latency Event-Driven Trading Engine

Deterministic Rust limit-order-book and matching engine with replay, portfolio accounting, risk controls, property tests, and reproducible local benchmarks.

  • Rust
  • Event-Driven
  • Matching Engine
  • Replay
  • Criterion
Ownership
Owned project
Timeline
August 2026
Status
Open-source systems project
  • Committed local measurements, with machine and toolchain recorded.
  1. InputEvent input
  2. RouterMulti-symbol router
  3. BookLimit order book
  4. FillsMatch / fill events
  5. P&LPortfolio / P&L

System architecture+3 more

Overview

A Rust event-driven simulation stack centered on price-time-priority market microstructure, deterministic replay, explicit pre-trade risk boundaries, and measured local performance.

Problem

Trading-system projects often jump to strategies or headline throughput before establishing deterministic matching, accounting, cancellation, risk controls, and testable replay.

My role

Designed and implemented the order book, matching, replay, portfolio/risk, strategy, testing, and benchmark layers, with a Python comparison baseline.

System architecture

Input

Event input

Router

Multi-symbol router

Book

Limit order book

Fills

Match / fill events

P&L

Portfolio / P&L

Risk

Risk controls

Strategy

Strategy boundary

Proof

Test / benchmark

What I built

  • FIFO price-time-priority limit order book.
  • Limit, market, and cancel operations.
  • Partial fills and multi-level sweeps.
  • Multi-symbol routing and deterministic JSONL replay.
  • Golden-file replay scenarios.
  • Average-cost positions, cash, realized/unrealized P&L, and equity.
  • Pre-trade limits, a loss-triggered kill switch, and post-kill cancellation.
  • Bounded strategy-plugin commands with market-making and momentum demos.
  • Property-based tests.
  • Criterion benchmarks and an hdrhistogram measurement harness.
  • A naive Python comparison baseline.
  • An experimental order pool and lock-free queue, isolated behind feature flags.
  • Mock/localhost paper WebSocket path only.

Technical decisions

  • Deterministic replay and accounting correctness precede strategy work.
  • Risk limits and a kill switch are explicit engine boundaries, not strategy concerns.
  • Experimental concurrency and allocator paths stay feature-gated.
  • The order-pool experiment was slower than ordinary vector churn and stayed isolated rather than being promoted as an optimization win.
  • Demo strategies make no alpha or profitability claim.

Testing and validation

  • 247 passing CI tests at the evidence snapshot.
  • Current main CI succeeded, as did the scheduled security/code scan.
  • Deterministic replay validated against committed golden scenarios.
  • Property-based tests over book invariants.
  • Release-build and experimental-feature suites documented in the public project evidence.

Measured evidence

  • 125 ns

    p50, 10K synthetic core workload (≈4.61M events/s)

    Committed local Criterion benchmark. Apple M4 Pro, 24 GiB, macOS 26.5.2, rustc 1.96.0.

    Local, machine-specific measurement — not a latency guarantee, an exchange measurement, or production throughput.

  • 83 ns

    p50, cancel resting order (≈3.10M events/s)

    Committed local Criterion benchmark on the same machine and toolchain.

    Local benchmark, same caveats.

  • ≈1.16M events/s

    Naive Python 10K baseline, same workload

    Comparison baseline run on the same machine to make the Rust figure interpretable.

  • 247

    CI tests passing

    Latest successful main-branch CI run 31980194986 (2026-08-16), rechecked 2026-08-18.

    Point-in-time count, not a live counter.

A matching engine whose behaviour is reproducible before it is fast: the same JSONL replay produces the same fills, accounting, and risk decisions every run, and the benchmark numbers are published with the machine that produced them.

Limitations

  • No real exchange adapter.
  • No durable production persistence.
  • No real capital, and no profitability evidence.
  • No production concurrency model.
  • Mock/localhost paper feed only.
  • “Low latency” names the project domain; it is not an exchange-grade claim.

Technology stack

  • Rust
  • Event-Driven
  • Matching Engine
  • Replay
  • Criterion
  • Property-based testing
  • hdrhistogram
  • Python
  • GitHub Actions