Skip to content

Execution Service

tien.nguyen edited this page Aug 15, 2026 · 3 revisions

Execution Routing

The execution routing engine is the automated order routing and algorithmic execution component of the Emporia Trading Platform. It receives order domain events, evaluates routing strategies (DMA, SMART, VWAP), decomposes parent orders into child slices, and interfaces with market execution venues (exchange matching engines and FIX gateways).

โ„น๏ธ This is no longer a separate service. It ran as execution-service on port 8087 and was merged into order-management-service, in the same way order-command-service was folded in before it. The three Kafka topics that carried orders between the two processes are gone; dispatch is now a direct in-process call through ShardedOrderDispatcher, sharded by order id so per-order ordering is preserved without a broker. See No Blocking DB on the Hot Path for why the hot path avoids network and database round trips.


๐Ÿ“Œ Service Specifications

  • Package: com.emporia.execution, inside order-management-service
  • HTTP Port: shares the OMS port 8086 (no port of its own)
  • Database Boundary: Stateless (Stores checkpoint snapshots in ExchangeCoreCheckpointStore and recovers active strategy state dynamically).
  • Primary Roles:
    • Algorithmic order routing (DMA, SMART, VWAP).
    • Best execution under National Best Bid and Offer (NBBO) rules via BestVenueSelector.java.
    • Intraday VWAP volume-weighted time-slicing via VwapSchedule.java.
    • Execution venue gateway integration (ExchangeCoreExecutionVenueGateway, FixExecutionVenueGateway).
    • Handing execution commands (FILL, REJECT, CANCEL) to ExecutionCommandHandler by direct call.

๐Ÿ—๏ธ Architecture & Component Flow

flowchart TD
    subgraph InboundEvents ["Order Domain Input (same JVM)"]
        DISP["ShardedOrderDispatcher<br/>sharded by order id"] -->|OrderDomainEvent| EEC["ExecutionEventConsumer"]
    end

    subgraph StrategyRouter ["Routing & Strategy Engine"]
        EEC --> SelectDestination{"Order Destination?"}
        SelectDestination -->|DMA| GatewayRouter["ExecutionVenueGateway"]
        SelectDestination -->|SMART| SmartEngine["BestVenueSelector (SOR)"]
        SelectDestination -->|VWAP| VwapEngine["VwapSchedule Algorithmic Slicer"]
    end

    subgraph Venues ["Execution Venues"]
        GatewayRouter --> ExchangeCore["ExchangeCoreExecutionVenueGateway (Disruptor RingBuffer)"]
        GatewayRouter --> FixGateway["FixExecutionVenueGateway (FIX 4.2/4.4 Protocol)"]
        GatewayRouter --> SimGateway["SimulatedExecutionVenueGateway"]
    end

    subgraph AlgorithmicSlices ["Parent-Child Algorithmic Orders"]
        SmartEngine -->|Child slice, direct call| OCH["OrderCommandHandler"]
        VwapEngine -->|Scheduled slice, direct call| OCH
    end

    subgraph OutboundExecutions ["Execution Outcome"]
        ExchangeCore -->|ExecutionCommand, direct call| ECH["ExecutionCommandHandler"]
        FixGateway -->|ExecutionCommand, direct call| ECH
        SimGateway -->|ExecutionCommand, direct call| ECH
    end
Loading

๐Ÿ”‘ Key Components & Routing Destinations

1. DMA (Direct Market Access)

  • Mechanics: Bypasses algorithmic slicing and routes the order directly to the designated venue gateway.
  • Venue Gateways:
    • ExchangeCoreExecutionVenueGateway: Ultra-low latency interface to in-memory LMAX Disruptor matching engine (exchange-core).
    • FixExecutionVenueGateway: Institutional FIX protocol (FIX 4.2/4.4) gateway.
    • SimulatedExecutionVenueGateway: In-memory venue simulator for testing.

2. SMART (Smart Order Routing - SOR)

  • Engine: BestVenueSelector.java
  • Mechanics:
    • Evaluates real-time Level-1 quotes across all listings for the instrument.
    • Applies NBBO Best Execution rules: routes BUY orders to the lowest Ask price and SELL orders to the highest Bid price.
    • If a single venue does not have sufficient depth, it splits the parent order into multiple child slice orders and submits them back through OrderCommandHandler.

3. VWAP (Volume-Weighted Average Price)

  • Engine: VwapSchedule.java
  • Mechanics:
    • Decomposes large parent orders into historical volume-weighted time buckets (buckets, durationMinutes, participationRate).
    • Uses TaskScheduler to periodically release child orders through OrderCommandHandler across the specified trading window.

โšก Self-Healing Startup Recovery

On application startup (ApplicationReadyEvent), ExecutionEventConsumer.recover() runs automatically:

  1. Calls TradingDataClient to fetch all un-cleared direct orders and active strategy states from order-management.
  2. Resubmits direct orders to venue gateways.
  3. Reschedules active SMART and VWAP strategy runtimes seamlessly without dropping active child order slices across service restarts.

Emporia Wiki


๐Ÿ“– Financial Domain & Terms


๐Ÿ›๏ธ System Architecture


โš™๏ธ Microservice Deep-Dives


๐Ÿ”— Quick Links

  • Repository: emporia
  • Tech Stack: Java 21 | Spring Boot 4.0.7 | React 19 | LMAX Disruptor | Aeron | gRPC
  • Coverage: 91.95% JaCoCo

Clone this wiki locally