Shadowell
  1. Shadowell
  2. Notes
  3. Budgeting latency: a per-hop accounting

EngineeringCore systems · December 2025 · 11 min read

Budgeting latency: a per-hop accounting

  • Engineering
  • Latency
  • Infrastructure
  • Inside the stack

Latency is not a number you quote. It is a budget you allocate, a distribution you own, and a regression test you never let go red.

People new to low-latency work ask "how fast is your system?" and expect a single figure. The honest answer is a question back: fast at what, measured where, at which percentile, under what load, racing whom? Every one of those qualifiers changes the answer by an order of magnitude.

Latency is only meaningful relative to someone

There is no absolute standard of fast. There is only whether you reach the order book before the participant whose flow you want to trade against, or after the one trying to trade against yours. That reframing matters, because it means the correct amount of engineering effort is finite and knowable. On some strategies, being in the top handful of participants is the entire business. On others, an extra microsecond is worth nothing, and the same week spent on the cost model is worth a great deal.

The hops

We keep a written budget for every path that matters, and every hop has an owner and a target. The shape of it looks like this. Numbers are illustrative; the discipline is the point.

HopBudgetWhat actually goes wrong
Venue → your rackphysicsCross-connect routing, patch panels, the fibre you did not measure
NIC → user space~1 µsKernel path instead of bypass; interrupt coalescing left on
Feed decode0.3–2 µsAllocation on the hot path; branch-heavy parsing; unaligned reads
Book build0.2–1.5 µsCache misses in the price-level structure; map lookups
Signal evaluation0.3–2 µsFloating-point stalls; work that could have been precomputed
Pre-trade risk0.2–1 µsLocks, logging, anything that touches the heap
Encode → gateway0.5–2 µsString formatting; copying; a syscall you forgot about
Wire → matching enginevenueSession throttles, sequencing, gateway queueing you cannot see

The hop everybody forgets is not in your code at all: the queue you are already in. A strategy that rests an order early and holds priority can beat a system two microseconds faster that arrives second. Queue position is latency by another name, and it is bought with modelling rather than hardware.

p50 is vanity. The tail pays the bills.

Median latency is the number that goes in decks. It is close to useless, because the moments that matter are precisely the moments when the system is under stress: a burst of messages, a volatility spike, an economic release. That is when information is most valuable and when your p99.9 shows up.

Figure 1 — the same system, quiet and burstingInteractive on the home page

A quiet system shows a tight distribution around 11 µs. Under a message burst the median barely moves while the 99.9th percentile grows by roughly two orders of magnitude, into the milliseconds.

Open the interactive figure

So we track distributions, not averages, and we look at latency conditioned on message rate. A system with a 12 µs median and a 900 µs tail under burst is not a 12 µs system. It is a 900 µs system that flatters itself when nothing is happening.

A predictable 8 µs beats a 5 µs average with a fat tail. You can build a strategy on a promise. You cannot build one on a hope.Core systems

Determinism beats speed

Jitter is the real enemy. The usual suspects, roughly in order of how often they are the culprit:

  • Allocation and garbage on the hot path; anything that can pause you will, at the worst moment
  • Page faults; memory not pre-touched or locked
  • Interrupts and kernel threads sharing your core; C-state transitions on an idle core
  • NUMA crossings; a thread pinned to the wrong socket for the NIC it serves
  • Shared L3 with a noisy neighbour process, including your own logging
  • Logging and metrics doing synchronous I/O because it was convenient in development

Measure where the wire is, not where the code is

Instrumenting your own code tells you what your code thinks happened. Hardware timestamps at the NIC tell you what happened. If those two disagree, the NIC is right. We take timestamps at capture, at decode, at decision and at send, and we keep the deltas as first-class metrics.

Then we gate it. A pull request that adds 200 nanoseconds to the critical path fails the build, exactly like one that breaks a unit test. Performance that is not defended in CI decays quietly, one reasonable-looking commit at a time.

c++// The whole regression gate, more or less. Run it in CI, fail the build.
static void bench_decode(benchmark::State& st) {
  const auto frames = load_golden_capture("xetra_2025-11-04.pcap");
  BookBuilder book;                     // pre-touched, pool-allocated
  for (auto _ : st) {
    for (const auto& f : frames)
      benchmark::DoNotOptimize(book.apply(f));
  }
  // kIsRate | kInvert reports seconds per message
  st.counters["sec_per_msg"] = benchmark::Counter(
      st.iterations() * frames.size(), benchmark::Counter::kIsRate |
      benchmark::Counter::kInvert);
}

// budget.yaml — checked in, reviewed like code
//   bench_decode.sec_per_msg: { target: 340e-9, ceiling: 380e-9 }

Where people waste their year

  1. Optimising the wrong hop. Shaving 300 ns off decode while sitting behind 40 µs of avoidable gateway queueing. Profile first, always.
  2. Buying speed you cannot use. If the edge decays over minutes, microseconds are a vanity purchase.
  3. Forgetting the alternative. The cheapest latency improvement is often a better model: predicting one tick further ahead beats a faster path to the wrong decision.

The fastest system in the world still loses to a system that knows when not to trade.

Terms used here

Queue position
Where your resting order sits in the priority queue at a price level. Being early is often worth more than being fast, and it is bought with modelling rather than hardware.