Design a Latency Diagnosis System for a Trading Path
Record where the time goes at every step of a low-latency trading path without slowing it down, and help engineers find which step, and which change, caused a latency problem.
Problem statement
Design a system for diagnosing latency problems in a low-latency system.
For this exercise, assume the system is one firm's automated trading path in a single colocated data center (servers placed next to the exchange).
A market-data update arrives from the exchange, a strategy process decides whether to trade, a risk check approves the order, an order gateway sends it to the exchange, and the exchange sends back an acknowledgment. Each of these steps is a hop, and most hops run on their own host.
Engineers watch tick-to-order latency: the time from a market-data update arriving to the order it caused leaving for the exchange. A normal median is about 10 microseconds, and the slow tail (the slowest 1 in 100 or 1 in 1,000 orders) matters as much as the median.
When latency gets worse, engineers need to see which hop got slower, for which strategy, host or exchange, starting when, and what changed around that time, such as a deployment, a configuration change or a busy host. They also need to open one slow order and see its full hop-by-hop timeline.
The measuring itself must never slow down or block the trading path. Missing measurements must show up as missing, never as fast. Fixing the problem automatically, paging an on-call engineer and the trading logic itself are out of scope.
What to build
- Record when each market-data update and each order enters and leaves every hop, and link them so one order's full journey, from the update that triggered it to the exchange acknowledgment, can be rebuilt.
- Show latency percentiles for each hop and end to end, sliced by strategy, host, exchange and time window, within a few seconds of the events.
- For any time window, list the slowest orders, show each one's hop-by-hop timeline, and line it up with the changes recorded around that time, such as deployments, configuration changes and host problems.
At scale
- For this exercise, assume up to 2 million hop timestamps per second at the market open, across about 50 hosts on the path.
- For this exercise, assume a normal tick-to-order median of about 10 microseconds and a 99th percentile of about 50 microseconds; recording a timestamp may add at most about 100 nanoseconds to a hop and may never wait on anything.
- For this exercise, assume host clocks must agree to within about 1 microsecond for hop times measured across two hosts to be trusted, and the system must show when they do not.
- For this exercise, keep every raw timestamp for the last 5 trading days and per-minute latency summaries for 1 year; a single order's timeline must open within about 2 seconds.