High-Performance Limit Order Book Simulator
This project is a lock-free limit order book simulator built in Java, designed around the LMAX Disruptor pattern. The motivation was to explore market microstructure realistically, while also testing how concurrency patterns from high-performance computing can be applied to trading systems. Traditional order book implementations often suffer from lock contention under high throughput; the Disruptor offered a way to bypass that limitation and push toward nanosecond-level latencies.
Motivation
I wanted to create a tool that could reproduce order-driven market dynamics without becoming bottlenecked by synchronization overhead. By implementing a matching engine that processes millions of messages per second, I could study how queues, matching priorities, and order flow interact—while also gaining practical experience with the concurrency models used in production trading infrastructure.
Features & Technical Details
-
Architecture:
- Core matching engine structured around the LMAX Disruptor ring buffer, ensuring lock-free handoff between producers (order submitters) and consumers (matching logic).
- Orders are timestamped, placed into the buffer, and matched using a price-time priority book.
- Supports both synthetic order generation and historical replay (via CSV ingestion), allowing tests under controlled or realistic conditions.
-
Order Types:
- Limit orders (buy/sell with price and quantity).
- Immediate-or-cancel and fill-or-kill as extensions.
-
Performance:
- Benchmarked to process millions of orders per second with microsecond latencies, demonstrating the advantage of the lock-free design.
Results & Observations
The simulator showed clear throughput improvements compared with traditional queue-based approaches. Lock contention was eliminated, and latency distributions became tighter and more predictable. Running synthetic stress tests revealed realistic emergent behaviors such as spread tightening under high liquidity and widening during bursts of cancels. It provided an accessible way to observe microstructure phenomena like order clustering, queue position effects, and volatility induced by order imbalance.
Future Work
- Extend the engine to handle more complex order types (stop-loss, iceberg).
- Introduce stochastic latency to simulate network jitter and exchange delays.
- Integrate with strategy backtesting frameworks, allowing systematic trading models to be tested against a realistic order book environment.
- Consider multi-asset and cross-market matching to explore correlated liquidity.
Reflections
Concurrency design was the main challenge. Achieving lock-free performance required careful memory management and attention to false sharing between threads. The trade-off was complexity: the Disruptor pattern is powerful but requires a mental shift from traditional queue-based programming. In the end, it provided both a valuable learning experience in high-performance systems and a concrete simulator for studying market microstructure.