KatInterview

Real-Time Risk Enforcement for Order Submission

System DesignModel answer
MediumModel answerSystem Designlow-latencyconcurrencyfinancial-systems

Last updated

Build a low-latency system that validates trading orders against risk limits before they leave your network, with atomic resource tracking.

You're building a risk enforcement layer for a trading platform. Every order submitted by traders must pass through a validation step that checks whether it complies with configured risk boundaries before reaching the market.

What the System Must Do

Your system sits between order generation and market connectivity. It must:

  • Validate each order against account-specific limits: maximum position sizes, order values, exposure caps, and loss thresholds
  • Track reserved capital so that approved orders consume available budget immediately, preventing multiple orders from using the same capacity
  • Default to rejection if the validation service becomes slow or unreachable

Performance Targets

  • Add no more than 10 microseconds to each order's journey
  • Handle 100,000 orders per second per gateway instance
  • Log every approval and rejection decision for audit purposes (this can happen outside the critical path)

What to Design

  1. Architecture: Show the main components and how data flows through the system
  2. Consistency mechanism: Explain how you prevent race conditions when multiple orders arrive concurrently for the same account
  3. Execution feedback: Describe how the system responds when the market reports that an order was filled, partially filled, or canceled
  4. Availability approach: Outline how you maintain the fail-closed guarantee while achieving high availability

Consider both the common case (normal operation under load) and edge cases (component failures, network delays, conflicting updates).

Hints

Hint 1

A 10 microsecond budget rules out network calls—think about what must be colocated

Hint 2

Concurrency control without locks: consider how data partitioning affects correctness

Hint 3

Reserved capacity must be held until the exchange confirms what actually happened