Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Pre-Trade Risk Checking System

Design a low-latency risk gate that prevents electronic orders from reaching an exchange when they would breach configured limits.

Problem statement

For this exercise, assume a colocated electronic-trading path of Strategy -> Order Manager -> Pre-Trade Risk -> Exchange Gateway -> Exchange. Every new or amended order must receive an authoritative risk decision before the gateway may transmit it; an order that breaches a limit is rejected and never leaves the firm.

Risk policies include versioned per-account, strategy, and instrument limits for order quantity, notional, price collars, gross or net exposure, and an emergency kill switch. An approval atomically reserves the relevant exposure so concurrent orders cannot each pass against the same remaining capacity.

Exchange acknowledgements, fills, cancellations, and rejects update or release reservations through idempotent lifecycle events; uncertainty remains conservatively reserved until reconciled.

Every decision records its order identity, policy version, relevant state version, outcome, and reason so it can be explained and replayed.

Assume one million order checks per second at peak across 10,000 strategies and 100,000 instruments, with a single hot strategy producing 100,000 checks per second and up to 10 million open reservations.

The risk gate should add no more than 250 microseconds at p99 in healthy operation and must fail closed rather than bypass checks when its authoritative state is unavailable. Lifecycle feeds may reach two million events per second and may be duplicated, delayed, or reordered.

A reviewed policy version should become active for its intended scope within one second without mixing old and new rules in one decision. Retain complete decision and lifecycle evidence for seven days for deterministic replay and keep compact audit outcomes for one year.

Exclude strategy generation, exchange matching internals, post-trade clearing, market-data construction, and jurisdiction-specific regulatory policy.

What to build

  1. Authorized risk operators can validate, publish, inspect, and activate immutable scoped policy versions and an emergency kill switch.
  2. The order path can idempotently obtain an approved or rejected decision, and approval atomically reserves exposure before transmission is allowed.
  3. Exchange acknowledgements, fills, cancellations, and rejects update risk state exactly once in effect despite duplicate, delayed, or reordered delivery.
  4. Operators can explain a decision from its policy and state versions, replay traffic deterministically, shadow-test changes, and observe health, latency, backlog, and reconciliation gaps.

At scalePractice assumption

  • Peak load is one million order checks per second across 10,000 strategies and 100,000 instruments, with one hot strategy producing 100,000 checks per second and up to 10 million open reservations.
  • The risk gate adds at most 250 microseconds at p99 in healthy operation and fails closed when the authoritative risk state cannot safely decide.
  • Order-lifecycle input peaks at two million events per second and is at least once, delayed, and potentially reordered; uncertain exposure remains reserved until an authoritative event or reconciliation resolves it.
  • Reviewed policy versions activate for their intended scope within one second, complete decision and lifecycle evidence is retained for seven days, and compact audit outcomes remain available for one year.