← Back to blog
Solution 4 min read 炬鲸团队

End-to-End Observability for Securities Trading: Tracing Order-to-Fill in Milliseconds

How to instrument a brokerage's core trading path — order, risk, matching, and fill — with business metrics, tiered sampling, and actionable alerts that cut mean time to detect from hours to minutes.

The observability problem in trading

A brokerage's core trading path is roughly client → gateway → risk → matching → clearing, with quotes, accounts, and order reporting systems in between. A single order crosses a dozen or more services, and a hiccup anywhere balloons into order latency or outright rejection. Traditional monitoring only watches each service's own CPU and logs, so the moment a link breaks everyone is flying blind, and triage degrades into "flip through logs service by service" — half an hour on average before you find anything.

Three business metrics that matter

For a trading system, the metrics worth watching are business metrics, not resource metrics:

  • Order latency: the end-to-end time from the gateway receiving an order to fill confirmation. Hold the P99, say at 50ms.
  • Fill rate: the share of orders that actually fill. A sudden drop usually means risk control is over-rejecting or matching is misbehaving.
  • Reject rate, bucketed by reason: is it a risk-control block, a parameter error, or a system fault? One glance tells you which.

All three are expressible in OBSERVE's PromQL with quantile aggregation:

histogram_quantile(0.99, sum(rate(order_latency_bucket[5m])) by (le))

The distinction matters in practice. CPU spikes are noisy and often benign; a fill-rate drop or a reject-rate spike is a direct, dollars-and-cents signal that something is wrong on the order path. Business metrics also give you a shared language with the trading desk, who don't care about your heap usage but do care about rejection reasons.

Tracing with tiered sampling

Trading is high-concurrency and low-latency, so full trace capture is unaffordable to store. The answer is tiered sampling: sample normal requests at 1%, but keep 100% of requests flagged as large orders or anomalies. OBSERVE supports dynamic sampling by span attributes, so any trace with order_amount > 1000000 or reject_reason != '' is retained in full.

During an incident, grab the trace_id from the alert, open the flame graph to find the offending span, then drill into the logs and SQL tied to that span. Matching timeouts, database lock waits, network retransmits — you peel down to root cause instead of grepping through services one by one.

Tiered, actionable alerting

Trading alerts must be tiered and actionable:

  • P1: order-latency P99 over threshold for three minutes, or a spike in reject rate — page via phone and SMS.
  • P2: a node pegged at 100% CPU or rising disk write latency — drain traffic first, then notify.
  • P3: trend alerts, such as matching latency creeping up for 30 consecutive minutes — intervene before it becomes P1.

Every alert carries the trace_id and the service topology at the time, so whoever receives it never has to ask "what's happening right now".

Dashboards that match the business

Alerting alone is not enough; the trading desk and the operations team need different views. Build one dashboard around the order path — order latency, fill rate, reject rate, top rejection reasons — and another around infrastructure health per node. The first is what you show during a trading incident; the second is what you look at afterwards. Keep both on one screen during market hours; there is no time to hunt for panels at 09:31.

Results and advice

After this setup went live at one brokerage, mean time to detect dropped from 45 minutes to 6, and order rejection fell 40%. The key lesson: build business metrics before you build tracing. Don't roll out full capture on day one — it is expensive and you will miss the point.

A rollout checklist that worked for us: (1) instrument the gateway and matching services first, since they bound the critical path; (2) publish the three business metrics as a single dashboard before anyone asks for traces; (3) set tiered sampling rules, and only then enable alerting, so the first week of noise does not bury the signal; (4) run a chaos drill — kill a matching node in staging — and confirm the trace and alert fire end to end before market hours.