KatInterview

Designing a Multi-Venue Cryptocurrency Order Routing System

System DesignModel answer
HardModel answerSystem Designdistributed-systemsfintechlatency

Last updated

Build an order-placement architecture that routes crypto trades to external exchanges, handling balance checks, partial fills, and venue failures.

Your team is building an order-placement backend for a cryptocurrency trading platform. Users submit buy and sell orders through your service, but you don't operate a matching engine. Instead, you forward orders to external cryptocurrency exchanges (venues), each with different APIs, rate limits, and reliability characteristics.

Your system must handle:

  • Order types: market orders (execute immediately at current price) and limit orders (execute only at a specified price or better)
  • Core operations: submit new orders, cancel existing orders, query order status
  • Multi-venue integration: connect to 3–10 external exchanges, each using different protocols (REST, WebSocket, FIX, or proprietary formats)
  • Balance management: verify sufficient funds and reserve them before sending orders externally
  • Execution tracking: process acknowledgments, partial fills, rejections, and reconcile with venue state
  • Quality attributes: high availability, correctness guarantees, audit trails, and low internal latency

Design the complete architecture: client-facing APIs, internal services, data models, the order lifecycle, routing decisions, failure scenarios, and scaling strategy.

Working Constraints

Define your own scale assumptions, but reasonable targets include:

  • Internal processing latency (before external venue call): p99 under 50ms
  • Peak order submission rate: several thousand orders per second
  • Execution report volume: 3–5× order volume (acknowledgments, fills, cancellations)
  • Multiple external venues with independent failure modes and rate limits
  • Custodial model: your platform holds user funds; you manage internal balances
  • Orders may fill partially across multiple venues
  • Strong consistency for balances and order state; eventual consistency acceptable for historical queries

Questions You Should Explore

Before diving into design, clarify:

  • Custody model: Do you hold user funds internally, or do users control keys and sign transactions?
  • Routing complexity: Should a single order be split and sent to multiple venues, or route to one venue only?
  • Order variants: Beyond market and limit, what about stop orders, immediate-or-cancel (IOC), fill-or-kill (FOK), good-till-canceled (GTC)?
  • Compliance: What regulatory requirements exist—sanctions checks, rate limits per user, audit retention periods?
  • Venue capabilities: Do exchanges accept client-assigned order IDs for idempotent submission? Do they provide sequence numbers in execution feeds?
  • Outage handling: When a venue goes down, should you reject new orders, queue them, or automatically reroute to another venue?

Hints

Hint 1

Start by separating concerns: API gateway, order management, venue adapters, and balance ledger should be distinct services with clear contracts.

Hint 2

Define the order state machine explicitly—what are the valid transitions from pending to filled, canceled, or failed? How do you handle the 'unknown' state after a network timeout?

Hint 3

Think through fund reservation carefully: when do you reserve, when do you release, and how do you handle partial fills that free up some reserved funds?