Project
Limit Order Book
Lock-free price-time priority matching. 10M+ orders/sec. Property-tested invariants.
Problem
Order matching must be absolutely correct under concurrent access. A single mis-match violates regulatory requirements.
Solution
Lock-free using ConcurrentSkipListMap. Immutable Order/Trade objects. Property-based testing across millions of randomized sequences.
Architecture
Bids: descending price map. Asks: ascending. Match at resting order's price. Partial fills leave residuals.
Implementation
@Test
@DisplayName("total traded quantity never exceeds order quantity")
void quantityConserved() {
Order sell = new Order(UUID.randomUUID(), AAPL, Side.SELL, 100, 100_00_0000L, 1000);
book.processOrder(sell);
long totalTraded = 0;
for (int i = 0; i < 5; i++) {
Order buy = new Order(UUID.randomUUID(), AAPL, Side.BUY, 30, 100_00_0000L, 2000 + i);
totalTraded += book.processOrder(buy).stream().mapToLong(Trade::quantity).sum();
}
assertEquals(100, totalTraded);
}Vision
Reference implementation of exchange-grade matching. Proving correctness and performance are not trade-offs.