KatInterview

Order Gateway Protocol Design for Connecting to a Trading Venue

System DesignModel answer
MediumModel answerSystem Designsystem-designmessaging-protocolsidempotency

Last updated

Design the session and application messages between an in-house order management system and an external venue, covering dedupe, sequencing, replay and recovery after disconnects.

You are building the link between a firm's internal order management system and an external trading venue reachable over the network. The firm sends orders; the venue answers with acknowledgements, rejections, cancellations, and executions.

The design has to cope with:

  • retransmissions after timeouts,
  • orders that fill in several pieces,
  • messages that arrive out of order or more than once,
  • dropped connections followed by reconnection.

Answer the following:

  1. Which message types are needed in each direction (firm to venue, and venue to firm)?
  2. What are the key fields of each message (identifiers, timestamps, quantities, prices, and so on)?
  3. How do you achieve idempotency, ordering, and exactly-once or effectively-once handling at the application level?
  4. How do you manage the session (heartbeats, sequence numbers, resend and replay), and how do you handle failure modes such as timeouts, duplicates, and reconnects?

State your assumptions about order types, throughput, and latency, and explain the trade-offs you make.

Hints

Hint 1

Split the design into two layers: a session layer (sequence numbers, heartbeats, replay) and an application layer (orders and execution events). Decide which guarantees belong to each.

Hint 2

Think about which identifier makes a retried order safe to resend, and which identifier lets you recognize a repeated execution event coming back. Why must a timed-out order never be resent under a new client ID?

Hint 3

Consider what happens when a fill crosses with your cancel request, when a gap appears in inbound sequence numbers, and when your process crashes between receiving a fill and updating positions.

Hint 4

Finish with a safety net: an independent feed or end-of-day reconciliation that catches anything the protocol-level guarantees miss.