Back to notes

High-frequency trading architecture

NIC RX → feed decode → local order book → signal and pre-trade risk → order encoding → NIC TX

Quant development

Liao Tonglang (ltl), May 1, 2026, 土法炼钢 · 系统与基础设施. 《高频交易架构:低延迟、内核旁路、FPGA 概览》 · Author’s system diagram (Chinese)

Contents
  1. Latency targets and execution priority
  2. Tick-to-trade latency budget
  3. Cross-connects, NUMA and PTP clocks
  4. Kernel bypass and packet I/O
  5. Price indexing, cache layout and core isolation
  6. SPSC rings and memory ordering
  7. Feed gaps, cancellations and risk limits
  8. FPGA datapath and pipeline timing
  9. Python prototypes and event-by-event replay
  10. Tail latency, sampling and load tests

Latency targets and execution priority

  • Latency tiers. The article uses sub-1 µs tick-to-trade as an ultra-low-latency (ULL) target, with decode, trigger and order entry on an FPGA. Its 1–10 µs software path uses dedicated polling cores, kernel bypass and preallocated memory.
  • Cross-market signals and stale quotes. When futures reprice before an ETF, the inter-city link consumes part of the response window. A market maker’s stale quote stays executable until the exchange applies the cancel.
  • FIFO and pro rata. Two orders rest at the same price, 80 lots first and 20 second. An incoming 10-lot order fills them 10/0 under FIFO and 8/2 under pure pro rata. CME also uses product-specific combinations.

Original §1.1 · Original §1.2 · CME matching algorithms

Tick-to-trade latency budget

  • Local wire-to-wire. Subtract the triggering packet’s hardware RX timestamp from the resulting order’s hardware TX timestamp on the same NIC clock. This includes decode, book update, decision, risk and transmit.
  • Exchange to exchange. Add feed packaging, both cross-connects and exchange ingress. The diagram totals about 7.1 µs, including 1.5 µs for decode and book update, 1.0 µs for signal and risk, and 1.3 µs for order encoding and transmit. The ACK return path is separate.
Stage times from exchange feed packaging to order ingress, with the acknowledgement shown separately.
Diagram by Liao Tonglang (May 1, 2026). The chart assigns 700 ns to a 5 m cross-connect. At the article’s 4.9 ns/m, propagation through the fibre alone is about 25 ns. Original SVG · Original §2.2

Original §2 · Linux hardware timestamps

Cross-connects, NUMA and PTP clocks

  • Links. A cross-connect links a colocated rack to the exchange. Propagation is about 4.9 ns/m in fibre and 3.3 ns/m through air. A narrow microwave link can carry the best bid and ask, with fibre for full depth and backup. Tick data for Chicago–New York imply a roughly 3 ms drop in one-way delay in 2010–2012.
  • RSS and NUMA. RSS hashes flows to RX queues. Match the NIC’s PCI numa_node to numactl --hardware. Place the polling core, packet pool and book on that node to avoid cross-socket memory traffic.
  • Cross-host timestamps. ethtool -T reports NIC timestamp capabilities. On a PTP client, ptp4l synchronizes the NIC hardware clock (PHC) to the master. phc2sys can align the system clock to the PHC. A cross-host interval includes the difference between the two clock offsets.

Original §3 · Chicago–New York study · Linux RSS · LinuxPTP

Kernel bypass and packet I/O

InterfacePacket and buffer handling
DPDK PMDrte_eth_rx_burst() returns up to N ready packets. rte_eth_tx_burst() returns the number queued. The application retries or frees the remaining rte_mbuf buffers.
OnloadOn supported adapters, LD_PRELOAD routes BSD socket calls to a userspace TCP/UDP stack. The application keeps recv() and send().
ef_viPost DMA buffers, poll RX events with ef_eventq_poll() and find the frame by receive ID. After processing, stage descriptors with ef_vi_receive_init() and notify the NIC with ef_vi_receive_push().
AF_XDPXDP selects a socket via XSKMAP. UMEM holds the packets. FILL supplies empty frame addresses and RX returns received descriptors. TX submits descriptors and COMPLETION returns reusable addresses. Binding with XDP_ZEROCOPY fails if the driver lacks support.

Transmit. With DMA, the NIC fetches the packet from host memory using a descriptor. With PIO, the CPU writes it to the card over PCIe MMIO. Cut-through PIO (CTPIO) can start transmitting during that write, reducing time to first byte on short orders.

Original §4 · DPDK ethdev · Onload · ef_vi API · AMD CTPIO · Linux AF_XDP

Price indexing, cache layout and core isolation

  • Book layout. Store aggregate quantity at index = price_tick - base_tick and maintain best-bid and best-ask cursors. A sliding window can rotate the array and clear reused slots, with sparse storage for far-away levels.
  • Protocol decode. Nasdaq ITCH adds, executions and deletes update the displayed book by order reference. OUCH handles order entry and private reports. An SBE decoder selects the template by templateId and skips blockLength bytes of root fields before reading groups and variable-length data.
  • Cache and branches. An array of structs (AoS) suits whole-event access. For price scans, separate price[] from qty[] (SoA). A 256-bit AVX2 comparison covers eight 32-bit prices. For an unpredictable conditional update, compare a conditional move (cmov) against a branch using cycles and branch misses on replayed traffic.
  • Huge pages and page faults. Preallocate packet pools and rings and touch each page at startup. A 2 MiB mapping covers the same range as 512 ordinary 4 KiB pages, reducing TLB pressure on large working sets.
  • Core isolation. Pin the thread and route unrelated interrupts away with IRQ affinity. nohz_full can suppress scheduler ticks on a core with a single runnable task, and rcu_nocbs offloads RCU callbacks. SMT siblings still share execution resources. Waking from a deep C-state can add tail latency.

Original §5 · Original §7.4 · Nasdaq ITCH · OUCH · FIX SBE · Linux CPU isolation

SPSC rings and memory ordering

  • Single producer, single consumer. For power-of-two capacity N, the slot is seq & (N - 1). Write the payload, then release-store the write index. The consumer acquire-loads that index, reads the payload and release-stores its read index. The producer acquire-loads the read index before reusing the slot.
  • Cursor traffic. Put the read and write indices on separate cache lines. Cache the peer’s index and refresh it on apparent empty/full. Publish once after writing a batch. One SPSC per feed avoids producers contending on a shared write index.
  • Zero-copy and reclamation. Pass a buffer index across the queue. Return it to the pool after the last reader, or after TX completion for a buffer still owned by the NIC. For read-mostly parameters, RCU publishes a new pointer and reclaims the old version after a grace period.

Original §7.1 · Original §7.8 · Linux circular buffers · RCU

Feed gaps, cancellations and risk limits

  • UDP multicast gaps. Deduplicate A/B feeds and fill gaps by channel packet sequence. If both lines miss a packet, suspend the affected book and buffer incrementals. CME MDP 3.0 aligns snapshots by LastMsgSeqNumProcessed and checks TransactTime if the boundary packet contains the same instrument.
  • Risk and cancels. Check price collars, size, position limits, message rate and self-trade controls before transmit. A fresh 10-lot buy that fills 3 while Pending Cancel still has 7 working. After cancellation, LeavesQty=0 and CumQty=3.
  • Standby and kill switch. A local standby follows the feed and runs shadow decisions. Fence the old sender and reconcile working orders against executions before takeover. A separate kill path uses mass cancel or individual cancels as the venue permits, and continues consuming reports until no orders remain working.

Original §3.7 · Original §2.5 · Original §7.9 · CME snapshot recovery · FIX matrix B.1.b

FPGA datapath and pipeline timing

  • On-card datapath. RX MAC → decode symbol and event → update top levels in on-chip RAM → test price, size, position and rate budget → fill price and size into a pre-encoded order → TX. The CPU updates threshold registers over PCIe.
  • Latency and initiation interval (II). At 250 MHz an eight-cycle pipeline takes 32 ns per input. If it achieves II=1, it can accept another input every 4 ns. #pragma HLS PIPELINE II=1 requests that interval. Read achieved II from the scheduling report and clock timing after place and route.
  • RTL, HLS and ASICs. RTL describes registers and combinational logic. HLS synthesizes a supported subset of C/C++. Inspect cycle-level state in simulation, probe board signals with an integrated logic analyzer (ILA), and test RX-to-TX with loopback. FPGA logic changes need a new bitstream. ASIC logic changes generally need new silicon.

Original §6 · AMD Vitis HLS

Python prototypes and event-by-event replay

  • Research and the hot path. Python replays PCAPs, computes features and sends parameters over a control channel. C++/Rust handles per-event packet I/O. Numba @njit, Cython and Pythran can compile numerical loops. Python object allocation and contention in GIL-enabled builds can still occur at the call boundary.
  • The Numba ring experiment. After JIT warm-up the article times a push/pop pair on one thread and compares it with deque and queue.Queue. Its batch version pays one cursor update per batch. Measuring cross-core visibility and cache-line transfers requires a separate producer and consumer on pinned cores.
  • Replay parity. Identify each feed event by channel, packet sequence and index within the packet. In recorded order, feed both implementations the same updates, order reports and parameters. Compare book state, order intent and inventory per event. At the first divergence, check rounding, overflow and event order. Shadow runs record intended orders.

Original §8 · Original §7.7 · Numba compilation modes

Tail latency, sampling and load tests

  • Queueing. If 50 messages arrive at an empty queue together and one thread takes 2 µs each, the last waits 98 µs and finishes at 100 µs. Record depth and drops separately for opening bursts, quiet flow and concurrent instruments.
  • Tail distribution. Compute TX minus RX per event, build a histogram of the differences and read P50, P99, P99.9, P99.99 and max. The slowest 0.01% of 10,000 events is one observation. Compute end-to-end P99 from event totals. Stage P99s are not additive.
  • The article’s benchmark. Its final example generates synthetic latencies. Each of ten runs warms up for 1,000 iterations, then records 100,000 samples. Compute P99 per run and std(P99) / mean(P99) across runs. On a live path, use paired hardware timestamps as the samples.
  • Jitter diagnostics. Use perf stat for cycles, branch misses and cache misses, perf record for hot code and perf c2c for contended cache lines. The hot thread appends event IDs and timestamps to a dedicated ring. Persist samples off-thread and count telemetry drops.

Original §10 · Original §5.7 · Linux perf c2c

Back to notes