Systems & building

The low-latency stack

∞structural
By . Reviewed 22 October 2026. As of 2026: a permanent feature of the market, not an edge that decays.

Kernel bypass, busy-polling, cache discipline, NUMA pinning: the engineering that shaves microseconds. Necessary for speed plays, overkill for most microstructure strategies.

The idea

The hot path, and the tail that hurts annotated diagramDG-STACK
The hot path ▼ market-data packet in NIC + bypass0.5–1 µs Decode0.1–0.5 µs Book0.1–0.5 µs Strategy0.5–3 µs Risk0.1–0.5 µs Order out0.5–1 µs median ≈ 2–7 µs tick-to-trade lock-free queue cold path logging · alloc · dashboards never blocks the hot line Latency distribution median ~5 µs p99 this is the trade you lose the median is a vanity metric; the tail is the strategy

What this shows. The hot path is the one tight line from packet in to order out; everything slow (logging, allocation) is pushed to a cold path that never blocks it, through a lock-free queue. Disciplined software lands a median of a few microseconds, but the engineering really lives in the tail. The p99 event, during a fast market, is the one you lose, so you optimise the tail, not the average.

What is the "hot path", and why is everything else kept off it?

The hot path is the sequence of code that runs on every market-data event that might lead to a trade: decode the packet, update the book, evaluate the signal, check risk, send the order. Logging, memory allocation, file I/O, admin and monitoring all move to a cold path on other threads, because anything the hot path waits on becomes part of your latency.

The hot path is therefore stripped down. It makes no allocations (memory comes from pre-built pools), no system calls, takes no locks and writes nothing to disk. Every piece of state it needs is already in memory, ideally already in cache. The cold path writes logs, persists fills and updates dashboards on separate cores, and talks to the hot path through a lock-free queue so the hot path never blocks. This discipline organises the whole system architecture: feed handler, book builder, strategy and order gateway form a tight, predictable line, and everything else is asynchronous.

Why is event-driven architecture the right shape?

Because trading is reactive: nothing happens until the market sends an event, whether a quote change, a trade or a timer. An event-driven design models exactly that with a loop that waits for the next event and dispatches it through the hot path. It avoids polling overhead, keeps one deterministic order of processing, and maps directly onto the incoming feed.

The loop is short: take the next event (a market-data message, an order acknowledgement, a clock tick), dispatch it to its handler, repeat. One thread, one ordering, no surprises about what ran when. That determinism is also what lets you backtest faithfully: the simulator replays the same event stream through the same loop, so production and backtest share the strategy code and the processing order.

Events come from the messaging layer: the multicast feed delivers book updates, the order session delivers execution reports, internal timers fire. Each is a small typed event the loop routes. This is the opposite of a request/response web service, where a handler may wait on a database. The constraint that follows is never block the loop, which is why everything slow lives on the cold path.

What is the difference between low latency and low jitter, and why does the tail matter more?

Latency is how long one event takes to process; jitter is how much that time varies. A system with a 5 µs median and an occasional 500 µs spike loses exactly when it matters, during the volatile bursts you most want to trade. So engineers watch the tail (p99, p99.9, max) rather than the average.

The worst case fires in fast markets, which is where the opportunity and the adverse selection are greatest. You plan around the worst case you will plausibly hit, so the median is a poor guide to whether you get filled.

A latency budget is built against a tail percentile, not the mean. The number that decides whether you win the contested trade is the high-percentile latency during a burst, which can be many times the median if jitter is uncontrolled.
Lp99=inf⁡{ ℓ:P(latency≤ℓ)≥0.99 },Lp99≫Lmedian  ⇒  jitter problemL_{p99} = \inf\{\,\ell : \mathbb{P}(\text{latency} \le \ell) \ge 0.99\,\}, \qquad L_{p99} \gg L_{\text{median}} \;\Rightarrow\; \text{jitter problem}

Jitter has many small sources: the OS pre-empting your thread, interrupts, cache misses, page faults, cross-socket NUMA access, lock contention and, in managed languages, garbage collection. Each is fought structurally. On Linux you pin the hot thread to a core the scheduler leaves alone: the kernel's isolcpus= boot option isolates a set of CPUs from general scheduling, and nohz_full= marks them as adaptive-tick CPUs so a core running a single task takes no scheduler tick (at least one CPU must stay behind for housekeeping). Then busy-poll instead of sleeping, pre-allocate and pre-fault memory, disable frequency scaling, keep data on one NUMA node, and avoid any code path that occasionally does something expensive. A latency budget is built against the tail because the tail is the trade you lose.

What is kernel bypass, and why DPDK / Solarflare?

The kernel's network stack adds microseconds and jitter to every packet through copies, interrupts and context switches. Kernel bypass lets your application read packets straight from the network card in user space. DPDK, a software framework, and Onload on Solarflare cards are two standard ways to do it, and both cut and stabilise inbound latency.

DPDK's Poll Mode Drivers are, in the project's words, "designed to work without asynchronous, interrupt-based signaling mechanisms": your process polls the NIC's receive rings directly, with no kernel, no per-packet interrupt and no copy. OpenOnload takes a different route to the same end. It accelerates TCP and UDP I/O for applications using ordinary BSD sockets on Linux and is binary compatible with existing programs, so you can often speed up a feed handler without rewriting its networking. Onload came from Solarflare, whose cards are now sold as AMD Solarflare. FPGA NICs go further still. Kernel bypass typically shaves single-digit microseconds and, more importantly, removes a large source of jitter from the inbound multicast feed.

The cost is a core busy-polling around the clock: it never sleeps waiting for an interrupt, so you pay in CPU and power for latency. That is a deliberate trade, and the tooling is mature and commercially available. Owning a kernel-bypass NIC is a purchase, which is why infrastructure is the price of entry, not the edge.

What are busy-polling, lock-free queues and cache-friendliness?

They are the three core hot-path techniques. Busy-polling has the thread loop checking for work instead of sleeping, trading CPU for zero wake-up latency. Lock-free queues pass data between threads without mutexes, so no thread blocks. Cache-friendliness lays data out so the CPU finds it in L1 or L2 rather than stalling on main memory.

A sleeping thread takes microseconds to wake when an event arrives, which is unacceptable jitter on the hot path, so the thread spins on the NIC ring and the input queue and reacts the moment data appears. The price is a fully occupied, power-hungry core: worth it on the critical path and nowhere else. The usual lock-free structure is a single-producer, single-consumer ring buffer. The LMAX Disruptor (Thompson, Farley, Barker, Gee and Stewart, 2011) is the best-documented example: a pre-allocated ring buffer that the authors report moving messages between threads with latencies "lower than 50 nanoseconds" and throughput above 25 million messages per second. A lock can block the hot path while another thread holds it; a lock-free design guarantees the hot thread always makes progress.

Cache-friendliness matters because the memory hierarchy is steeply uneven. Drepper's "What Every Programmer Should Know About Memory" (2007) measures an L1 hit at a few cycles and a trip to main memory at a couple of hundred, roughly two orders of magnitude. So you keep hot data small and contiguous (arrays rather than linked structures) and lay out the book so a lookup touches few cache lines. You also avoid false sharing, which the Disruptor paper explains well: two variables in one cache line, written by different cores, make those cores contend for the line even though they never touch each other's data. At microsecond budgets, cache misses are a dominant cost.

The latency gap between cache and main memory is about two orders of magnitude, so at a single-digit-microsecond budget a handful of avoidable cache misses can be the difference between winning and losing the event.
tL1≈1 ns  ⋘  tDRAM≈100 ns⇒tDRAMtL1≈100t_{\text{L1}} \approx 1\,\text{ns} \;\lll\; t_{\text{DRAM}} \approx 100\,\text{ns} \quad\Rightarrow\quad \frac{t_{\text{DRAM}}}{t_{\text{L1}}} \approx 100

These three, plus core pinning and pre-allocation, are what take competent software from tens of microseconds to single digits: the kernel-bypass software tier that sits below the silicon frontier.

C++ or Rust: does language choice matter?

Yes, because the hot path needs control over memory and layout. In practice that means C++, the incumbent with the most low-latency libraries and FPGA toolchain support, or Rust, which gives the same control with memory safety and a growing share of new work.

What you cannot have on the hot path is a collector that pauses at times of its choosing. A garbage-collection pause of unpredictable length wrecks tail latency. That does not rule out managed languages entirely: LMAX built an exchange in Java, and the Disruptor's answer was to pre-allocate its ring entries so the hot path allocates nothing, which the authors note "eliminates issues in languages that support garbage collection". So a GC language can work if you write it like C. Most firms skip the discipline and reach for C++ or Rust, where there is no collector at all. C++ has decades of low-latency idioms and its toolchains for FPGA co-design; Rust removes a class of memory bugs that are costly in a system that can lose money in microseconds.

Python's place is real but bounded: research (backtests, signal exploration, the research-to-production pipeline), not the live hot path. A common shape is research in Python and the production path in C++ or Rust, and reconciling the two is its own discipline. LLM assistants now help with translating a prototype into a C++ or Rust hot path, suggesting cache-friendly layouts and spotting an allocation where there should be none, while the judgement about what to optimise and how to validate it stays human (see what AI changes for HFT).

How do you actually measure latency?

You timestamp the same event at several points (packet at the NIC, decode done, order on the wire) and record the distribution, not the average. The most trustworthy numbers come from hardware NIC timestamps and an external wire capture, a passive tap that timestamps packets independently, because software clocks disturb what they measure. Report the median, p99, p99.9 and max.

HdrHistogram, written by Gil Tene, is a widely used tool for recording latency distributions across the full percentile spectrum, so the plot shows the spikes a single mean would hide. For where the time goes, take internal timestamps at hot-path stages, for example from the CPU's rdtsc counter, which gives a stage-by-stage breakdown. For ground truth on tick-to-trade, use the external timestamp so your own instrumentation adds neither latency nor jitter.

Clock accuracy has a regulatory side too. Under RTS 25 (Delegated Regulation 2017/574), EU firms using a high-frequency algorithmic trading technique must keep business clocks within 100 microseconds of UTC and timestamp to a granularity of one microsecond or better. The trap in all of this is measurement that lies: logging every event on the hot path, or calling an expensive clock, changes the thing measured, so you sample, use cheap counters and aggregate off the hot path. The breakdown feeds the latency budget: once you know where the microseconds go, you can decide which stage is worth attacking and which is already small enough to ignore.

Worked example: a tick-to-trade budget

Take a schematic breakdown for a kernel-bypass software system in colocation. The ranges are illustrative (measure your own; the point is the shape), and tick-to-trade is additive, so the budget is the sum of the stages from "market-data packet in" to "order out".

Tick-to-trade is the sum of the stage latencies. With disciplined kernel-bypass software in colocation the median lands in the low single-digit microseconds; the p99 is where the engineering actually lives.
Ttick-to-trade=tNIC+tdecode+tbook+tstrategy+trisk+tgatewayT_{\text{tick-to-trade}} = t_{\text{NIC}} + t_{\text{decode}} + t_{\text{book}} + t_{\text{strategy}} + t_{\text{risk}} + t_{\text{gateway}}

Stage by stage, with the lever that attacks each: NIC + kernel bypass (packet to user space) about 0.5–1 µs, the lever being DPDK or Onload; decode of the binary protocol about 0.1–0.5 µs, the lever a fixed-offset layout with no parsing; book update about 0.1–0.5 µs, the lever a cache-friendly book; strategy/signal about 0.5–3 µs, the lever tight hot-path code over pre-computed state; pre-trade risk check about 0.1–0.5 µs, in-line with no I/O; and order encode + send about 0.5–1 µs, the lever a binary order protocol over kernel bypass. The lows add to 1.8 µs and the highs to 6.5 µs, so the median tick-to-trade lands at roughly 2–7 µs.

The lesson is in the gap between median and tail. Disciplined software can hit that median, but the p99 is where the work is: uncontrolled, the 99th-percentile event might take 30 µs (an illustrative figure) because a thread was pre-empted or a cache line was cold, and that is the event you lose in a fast market. Core isolation, busy-polling and a hot path that allocates nothing keep the tail close to the median. An FPGA path collapses decode, strategy and encode into tens-to-hundreds of nanoseconds wire-to-wire, the only way past the software floor, at a cost. Be careful with the record numbers: in June 2024 STAC reported a minimum STAC-T0 network-I/O latency of 13.9 ns for an AMD Alveo UL3524 running Exegy's nxFramework, but that benchmark runs trivial trading logic and reports a minimum, not what a real strategy achieves. Compare your strategy's actual requirement with the software figures above before spending anything on speed. Most strategies live well above this floor, where low-jitter software is decisive and far cheaper than silicon.

Sources

  1. Drepper, U. (2007). "What Every Programmer Should Know About Memory". Red Hat, 21 November 2007. akkadia.org
  2. Thompson, M., Farley, D., Barker, M., Gee, P. and Stewart, A. (2011). "Disruptor: High performance alternative to bounded queues for exchanging data between concurrent threads". LMAX, May 2011. lmax-exchange.github.io
  3. DPDK Project. "Programmer's Guide: Overview". doc.dpdk.org
  4. AMD/Xilinx. "OpenOnload: high performance user-level network stack" (source repository). github.com
  5. Linux kernel documentation. "The kernel's command-line parameters" and "NO_HZ: Reducing Scheduling-Clock Ticks". kernel parameters, NO_HZ
  6. Commission Delegated Regulation (EU) 2017/574 (RTS 25, accuracy of business clocks), 7 June 2016. eur-lex.europa.eu
  7. STAC. "STAC Report: New STAC-T0 results with an Exegy/AMD FPGA solution", 25 June 2024. docs.stacresearch.com
  8. HdrHistogram (Gil Tene, original author). hdrhistogram.github.io

Where this fits