Skip to content

Latency anomaly detection is a distinct engineering layer above measurement correctness. Once a trading platform has accurate latency measurements — free of coordinated omission, stored in high-dynamic-range histograms — the question becomes how to surface anomalies automatically. The decision between absolute thresholds and percentile-ratio rules determines whether gradual degradation is caught or missed. Percentile-ratio rules detect tail spreading relative to the current median; absolute thresholds fail silently when the baseline drifts. This post surveys the detection machinery: what sits above measurement, why static bounds fail, and how percentile divergence catches what they miss.

Measurement correctness is prerequisite, not detection#

Correct latency measurement is a solved prerequisite. Detection is the distinct layer that consumes those measurements. HdrHistogram provides hybrid exponential-linear bucketing to maintain percentile precision across wide ranges — one microsecond to 100 seconds — in a compact 31-kilobyte footprint[1]. Coordinated omission correction addresses the measurement bias where closed-model load generators hide tail latencies by coordinating their sampling with system delays. The correction requires static schedules and latency adjustment using recorded intervals[2].

These techniques are well-covered in the peer record. One institutional trading platform uses HdrHistogram percentile analysis alongside Linux perf tracing to identify jitter sources, reducing maximum latency from 11 milliseconds to 14 microseconds through CPU isolation and frequency stabilisation[5]. Coordinated omission correction, when applied to YCSB benchmarks, reveals actual P99 latencies of 665 milliseconds where uncorrected measurements report 249 microseconds — a factor of 2,667. The measurement hygiene is settled.

Detection is the next question. Given correct measurements — percentiles stored without sampling bias, distributions captured without coordinated omission — how does machinery surface anomalies without manual intervention? The machinery operates on histogram inputs, not raw samples. It asks whether the current distribution has diverged from recent history in a way that signals degradation. That divergence can be a spike, a drift, or a tail spreading away from the median. Detection catches the divergence; measurement provides the inputs.

The simplest detection approach is absolute thresholds. A rule like "alert when P99 exceeds 500 microseconds" requires no state beyond a single comparison. But this approach fails in predictable ways when baselines drift.

Three-layer stack: measurement correctness feeds detection machinery feeds surfacing layer.
Detection machinery sits above measurement correctness as a distinct engineering layer, consuming histogram inputs and producing alerts for the surfacing layer.

Absolute thresholds fail when baselines drift#

Static thresholds require prior knowledge of acceptable latency. A bound like "P99 > 500 μs" assumes 500 microseconds is the line between acceptable and anomalous. But acceptable latency depends on workload, time of day, and market regime. A midday orderbook update tolerates higher latency than a pre-market execution path. The threshold that works for one does not transfer to the other.

The failure mode is silent. When the system improves or degrades gradually, the threshold becomes stale. Consider a path whose P99 latency drifts from 200 microseconds to 400 microseconds over six weeks. The drift is monotonic — 3 microseconds per day — but no single day crosses the 500-microsecond bound. No alert fires. The baseline drifted with the degradation. By the time the threshold triggers, P99 has doubled relative to its original value, and the compounded drift has already priced into execution quality.

The problem is structural. Absolute thresholds encode a fixed expectation about what latency should be. They do not adapt to the current operating regime. If the system speeds up — P99 drops from 200 microseconds to 100 microseconds because a kernel patch eliminates contention — the 500-microsecond threshold remains silent. It no longer detects anomalies at the new scale. The threshold is either too tight (alert fatigue when the system is slow but acceptable) or too loose (missed anomalies when the system degrades from a faster baseline).

The failure is not loud. There is no crash, no divergence visible in a dashboard. The machinery continues to operate. Alerts do not fire. The only feedback channel is a trader reporting degraded execution quality — a signal that lags the anomaly by hours or days. Absolute thresholds cannot catch what they were not calibrated to expect.

Percentile-ratio rules solve this by detecting tail spreading relative to the current median. The detection compares P99 to P50, not to a static bound.

Percentile-ratio rules detect tail spreading#

Percentile-ratio detection triggers when P99 exceeds a multiple of P50 for a sustained window. A typical rule is "alert when P99 > 3 × P50 for 15 minutes." The mechanism is explicit. P50 is the current baseline — the median latency under the present workload. P99 is the tail. The ratio P99 / P50 captures tail spreading independent of absolute scale. If the system speeds up and P50 drops, the ratio stays stable. If the tail spreads — P99 rises faster than P50 — the ratio triggers[3].

The rule adapts to the operating regime. When P50 is 100 microseconds, a P99 of 300 microseconds triggers the 3× ratio. When P50 drops to 50 microseconds, the trigger point drops to 150 microseconds. The detection is relative, not static. It does not require prior knowledge of acceptable latency. It asks whether the tail is spreading away from the median now.

Contrast this with absolute thresholds. A static bound like "P99 > 500 μs" cannot distinguish between a system running at P50 = 100 μs with tail spreading (P99 / P50 = 5, anomalous) and a system running at P50 = 400 μs with tight distribution (P99 / P50 = 1.25, healthy). Percentile-ratio rules make this distinction. They detect the shape of the distribution, not just its magnitude.

A common misconception is that automated anomaly detection implies machine-learning-based magic. Google SRE explicitly discourages "magic systems that try to learn thresholds or automatically detect causality"[3]. But percentile-ratio rules are not magic. They are deterministic, explicit, and inspectable. The ratio threshold is a parameter — typically 3.0 for latency-sensitive paths, adjusted per workload. The sustained-window check (15 minutes) prevents spurious alerts on transient spikes. The logic is one comparison, readable in a single line.

# Percentile-ratio anomaly detection — pseudocode
def check_anomaly(histogram, k=3.0, window_minutes=15):
    p50 = histogram.percentile(50)
    p99 = histogram.percentile(99)
    ratio = p99 / p50 if p50 > 0 else float('inf')
    if ratio > k:
        # Sustained check over window omitted for brevity
        return Alert(ratio=ratio, p50=p50, p99=p99)
    return None

The code block above shows the shape of the detection rule. The logic is explicit. The ratio k is tunable. The alert reports the ratio, P50, and P99 — not just a boolean flag. An operator reviewing the alert sees the numbers that triggered it. There is no learned model, no hidden threshold. The detection is automated in the sense that it runs without manual intervention, not in the sense that its logic is opaque.

Statistical tests like Anderson-Darling provide more rigorous tail-sensitive distribution comparisons[4]. The Anderson-Darling test places more weight on tail deviations than Kolmogorov-Smirnov, making it suitable for detecting latency distribution shifts. Alpha Equations does not implement published statistical standards directly. The detection machinery uses its own logic, drawing on statistical principles but not claiming conformance to a specific test. Percentile-ratio rules are simpler, faster, and sufficient for the operating regime. They trade statistical rigour for sub-microsecond overhead.

The cost of this approach is calibration complexity. Percentile-ratio detection requires tuning the ratio threshold per workload and doubles the histogram state.

Time-series showing P99 diverging from P50, illustrating tail spreading that percentile-ratio rules detect.
Percentile divergence visualised: P99 spreads away from P50 over time while the median remains stable, signalling tail degradation that absolute thresholds would miss.

The calibration trade-off#

Percentile-ratio detection requires maintaining two running percentile estimates — P99 and P50 — rather than one. HdrHistogram already stores full distributions in compact form, so doubling the state means tracking two percentile values per histogram. The memory overhead is marginal. A single HdrHistogram covering the range 1 microsecond to 1 minute with 3 significant digits consumes 31 kilobytes[1]. Doubling this for two percentile estimates adds 31 kilobytes. The cost is measured in kilobytes, not megabytes.

The harder cost is the sensitivity parameter. The ratio threshold k determines when an alert fires. Too tight — k = 1.5 — and the machinery produces alert fatigue. Spurious alerts fire on normal variance. A transient queue depth rise that pushes P99 to 1.6 × P50 for two minutes is not an anomaly; it is operating noise. Too loose — k = 5 — and the machinery misses real anomalies. A threshold that only triggers when P99 is five times P50 catches catastrophic events, not gradual degradation.

There is no universal k. The threshold must be tuned per workload, per market regime. An orderbook update path with P50 = 50 μs and typical variance of ±10 μs tolerates k = 3. A market-data ingestion path with P50 = 5 μs and variance ±1 μs requires k = 2 to catch tail spreading early. The tuning process starts conservative — high k, few alerts — and tightens iteratively as false negatives are reported by traders. Each tightening step risks increasing false positives until the machinery learns the workload's natural variance.

The calibration is not one-time. Market regimes change. A pre-market auction phase has different latency characteristics than continuous trading. A session with high message rates stresses the system differently than a quiet session. The ratio threshold that works in one regime may produce false positives or false negatives in another. The machinery must either maintain regime-specific thresholds or use a conservative global threshold and accept lower sensitivity.

The memory overhead is small. The calibration complexity is the real trade-off. Percentile-ratio rules detect what absolute thresholds miss, but they introduce a parameter that must be tuned, maintained, and revised as the system evolves. The feedback loop that drives this tuning is asymmetric.

The feedback loop is asymmetric#

False positives are actionable by developers. When an alert fires and investigation reveals no anomaly, the spurious alert is recorded. The pattern — time of day, message rate, specific path — is identified. The detection logic is corrected. Either the ratio threshold k is loosened for that workload, or the sustained-window check is lengthened to filter transient variance. The correction is fast. The feedback channel is internal. The machinery observes its own false positives because they produce visible alerts.

False negatives are unobservable by the machinery. A missed anomaly produces no alert. The detection machinery has no signal that an anomaly occurred and was missed. The only feedback channel is external observation by traders. A trader notices degraded execution quality. The trader reports the degradation. An operator investigates historical latency data and discovers that P99 crept up gradually without triggering an alert. The detection logic is corrected by tightening the threshold. But the feedback lag is hours or days. The drift has already compounded.

The asymmetry shapes how detection evolves. False-positive correction is a tight loop. Spurious alerts fire, developers investigate, logic is refined. The machinery improves against alert fatigue iteratively. False-negative correction is a slow loop. Anomalies are missed, traders report degraded execution, thresholds are tightened retroactively. The machinery drifts blind against missed anomalies until external feedback arrives.

This asymmetry is structural, not a failure of the detection machinery. No production system Alpha Equations is aware of solves this cleanly. Automated detection can observe what it surfaces — the alerts it fires. It cannot observe what it fails to surface — the anomalies it misses — without an external ground truth. Traders are that ground truth. But trader feedback lags the anomaly, sometimes by hours. By the time the feedback arrives, the anomaly has already priced into execution quality.

The detection machinery refines itself against false positives. It drifts blind against false negatives. The calibration process is ongoing, never converged. Each regime change, each workload shift, each system upgrade resets part of the calibration state. The hard problem is making false negatives observable without external reporting.

The hard problem is making false negatives observable without external reporting. Latency anomaly detection machinery can refine its rules when developers review spurious alerts, but it has no mechanism to know what it missed. A silent degradation that traders eventually notice is a lagging signal — the drift has already compounded. The challenge is designing detection that surfaces its own blindspots before they become visible in execution quality. No production system Alpha Equations is aware of solves this cleanly.