Skip to content

Execution Service

tien.nguyen edited this page Jul 30, 2026 · 1 revision

Execution Service

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


📌 Service Specifications

  • Directory: execution-service
  • HTTP Port: 8087
  • 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).
    • Publishing execution commands (FILL, REJECT, CANCEL) to emporia.execution.commands.v1.

🏗️ Architecture & Component Flow

flowchart TD
    subgraph InboundEvents ["Order Domain Input"]
        K1[["Kafka: emporia.orders.v1"]] -->|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 -->|Publish Child Slice| K2[["Kafka: emporia.order.commands.v1"]]
        VwapEngine -->|Publish Scheduled Slice| K2
    end

    subgraph OutboundExecutions ["Execution Outcome Stream"]
        ExchangeCore -->|Publish ExecutionCommand| K3[["Kafka: emporia.execution.commands.v1"]]
        FixGateway -->|Publish ExecutionCommand| K3
        SimGateway -->|Publish ExecutionCommand| K3
    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 produces them back to emporia.order.commands.v1.

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 into emporia.order.commands.v1 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-service.
  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.

Clone this wiki locally