Skip to content

Exchange Core Integration

tien.nguyen edited this page Jul 30, 2026 · 2 revisions

Exchange-Core Integration

The execution-service integrates with exchange-core, an ultra-low latency, in-memory matching engine powered by the LMAX Disruptor ring-buffer pattern.


๐Ÿ“ฆ Installation & Dependency

exchange-core is an external dependency hosted at https://github.com/nvxtien/exchange-core.

To build Emporia locally, developers must clone and install exchange-core into their local Maven repository (~/.m2/repository):

git clone https://github.com/nvxtien/exchange-core.git
cd exchange-core
mvn clean install

โšก High-Frequency Matching Engine Architecture

exchange-core provides sub-microsecond order book matching, deterministic sequence execution, lock-free ring buffers, and binary serialization.

flowchart LR
    subgraph EmporiaSystem ["Emporia Microservice Ecosystem"]
        OMS["Order Management Service"]
        KafkaOrderLog[["Kafka: emporia.orders.v1"]]
        ExecService["Execution Service (:8087)"]
        KafkaExecCmds[["Kafka: emporia.execution.commands.v1"]]
    end

    subgraph ExchangeCoreEngine ["Exchange-Core Engine"]
        Adapter["ExchangeCoreAdapter"]
        RingBuffer["LMAX Disruptor RingBuffer"]
        MatchingEngine["In-Memory OrderBook Core"]
        RiskEngine["Pre-Trade Risk Engine"]
    end

    OMS --> KafkaOrderLog
    KafkaOrderLog --> ExecService
    ExecService --> Adapter
    Adapter --> RingBuffer
    RingBuffer --> RiskEngine
    RiskEngine --> MatchingEngine
    MatchingEngine -->|Execution Result| Adapter
    Adapter --> KafkaExecCmds
    KafkaExecCmds --> OMS
Loading

๐Ÿ”‘ Key Integration Components

1. ExchangeCoreAdapter

  • Located in execution-service.
  • Translates Emporia domain TradingOrder commands (CREATE, CANCEL, MODIFY) into zero-allocation CommandOrder primitives accepted by the Disruptor ring buffer.
  • Map venue execution fills back to emporia.execution.commands.v1 Kafka events.

2. Lock-Free Single-Writer Principle

  • exchange-core isolates order matching to single-threaded ring buffer handlers to eliminate lock contention, atomic CAS overhead, and garbage collection pauses during high market activity.

3. Risk Seeding & Snapshots

  • exchange-core publishes durable snapshots and risk seed metrics to portfolio-service (:8088), ensuring position balances remain synchronized across system restarts.

๐Ÿงช Performance & Benchmark Attributes

  • Order Ingestion Rate: Up to 5,000,000 operations/second per core.
  • Matching Latency: 99.9th percentile $< 5$ microseconds.
  • Failover Recovery: Journal-backed state replay upon service startup.

Clone this wiki locally