Deterministic Limit Order Book (LOB) for Sub-Microsecond Matching
A production-grade, ultra-low latency (ULL) trading system built in Java, demonstrating HFT-level performance engineering across 5 integrated services.
βββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββ
β β β Aeron Cluster (Raft) β β β
β FIX Gateway ββββββΆβ βββββββββββββββ ββββββββββββββββ ββββββΆβ Response Gateway β
β (Ingress) β SBE β β Sequencer ββββ Matching β β SBE β (Egress) β
β β β β (Spinal β β Engine β β β + HDRHistogram β
β β’ TCP/NIO β β β Cord) β β (Brain) β β β β’ P99.99 tracking β
β β’ FIX Parser β β β β β β’ SIMD/AVX β β β β’ SBEβFIX encode β
β β’ FIXβSBE β β β β’ Total β β β’ Off-heap β β β β
β β’ Zero-alloc β β β Order β β LOB β β β β
31: βββββββββββββββββββ β βββββββββββββββ ββββββββββββββββ β ββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββββββββββ
β Warmup Service (AOT/CDS) β
β β’ JIT training runs β
β β’ CDS archive generation β
β β’ GraalVM PGO support β
ββββββββββββββββββββββββββββββββββββββ
| Technique | Where | Why |
|---|---|---|
| Zero Allocation | FIX parser, SBE codecs, matching engine | Eliminate GC pauses β no objects created on hot path |
| SIMD Vectorization | VectorizedPriceScanner |
Compare 8 price levels per CPU cycle (AVX-512) |
| Off-Heap Memory | OffHeapOrderBook |
64-byte cache-line-aligned order slots via Agrona UnsafeBuffer |
| SOA Layout | Order book price arrays | Structure-of-Arrays enables SIMD-friendly contiguous memory access |
| SBE Encoding | All inter-service messaging | Flyweight codec with zero-copy reads β no deserialization |
| Aeron Cluster | Sequencer | Raft consensus for deterministic total ordering |
| Fixed-Point Arithmetic | Prices | long scaled by 10βΈ β eliminates floating-point non-determinism |
| Core Pinning | All services | taskset -c N eliminates context-switch jitter |
| ZGC | JVM flags | Generational ZGC for sub-millisecond pause times |
chronos/
βββ chronos-schema/ # SBE message codecs (flyweight encoders/decoders)
βββ chronos-core/ # Domain model + off-heap order book
βββ chronos-matching/ # SIMD matching engine (Vector API)
βββ chronos-sequencer/ # Aeron Cluster service (Raft)
βββ chronos-fix-gateway/ # FIX protocol ingress
βββ chronos-response-gateway/# Execution report egress + latency tracking
βββ chronos-warmup/ # JIT training & AOT cache generation
βββ chronos-benchmarks/ # JMH + wire-to-wire + JFR zero-GC proof
- JDK 21+ (GraalVM CE recommended for faster JIT warmup)
- Gradle 9.x (wrapper included)
# Build all modules
./gradlew build
# Run JMH benchmarks (SIMD vs scalar, SBE vs string-based)
./gradlew :chronos-benchmarks:jmh
# Run wire-to-wire benchmark (1M orders)
./gradlew :chronos-benchmarks:run
# Run warmup training
./gradlew :chronos-warmup:run
# Start the sequencer (Aeron cluster node)
./gradlew :chronos-sequencer:run
# Start the FIX gateway (TCP port 9876)
./gradlew :chronos-fix-gateway:run
# Start the response gateway
./gradlew :chronos-response-gateway:runFor detailed benchmark results, methodology, and the Linux optimization guide, please see BENCHMARK_GUIDE.md.
- FIX Parsing: 110ns (vs 542ns QuickFIX/J)
- Wire-to-Wire Latency: < 50Β΅s (Linux Optimized)
- Zero GC: Verified via JFR on critical paths.
java -XX:+UseZGC \
-XX:+ZGenerational \
-Xms8g -Xmx8g \
-XX:SoftMaxHeapSize=6g \
--add-modules jdk.incubator.vector \
--add-opens java.base/sun.misc=ALL-UNNAMED \
-jar chronos-sequencer.jarGC Selection:
- Production: ZGC with generational mode (sub-millisecond GC pauses)
- Benchmarking: Epsilon GC (no-op GC for zero-allocation verification)
- Development: G1GC (default, balanced)
See docs/gc-selection-guide.md for detailed GC configuration guidance.
# Isolate cores 2-5 from the OS scheduler
# Add to kernel boot params: isolcpus=2-5 nohz_full=2-5
taskset -c 2 java -jar chronos-sequencer.jar
taskset -c 3 java -jar chronos-fix-gateway.jar
taskset -c 4 java -jar chronos-response-gateway.jar# Step 1: Train and dump class list
java -Xshare:off -XX:DumpLoadedClassList=chronos.classlist -jar chronos-warmup.jar
# Step 2: Create CDS archive
java -Xshare:dump -XX:SharedClassListFile=chronos.classlist -XX:SharedArchiveFile=chronos.jsa
# Step 3: Run with CDS
java -Xshare:on -XX:SharedArchiveFile=chronos.jsa -jar chronos-sequencer.jarThese features are currently in preview/incubator but will enhance CHRONOS when stabilized:
| Feature | JEP | Benefit |
|---|---|---|
| Project Valhalla (Value Classes) | JEP 401 | Eliminate object headers for Order/PriceLevel β better cache density |
| Project Panama (FFM API finalized) | JEP 454 | Replace Unsafe with MemorySegment + Arena for safer off-heap access |
| Vector API (finalized) | JEP 489 | Remove --add-modules jdk.incubator.vector flag |
| Project Leyden (AOT Cache) | JEP draft | Native AOT cache replacing CDS for instant startup |
Apache License 2.0