HFT: The Physics of Nanoseconds
Why light is too slow. Microwave networks, Kernel Bypass (Solarflare), and why Fiber Optic cables are obsolete for price discovery.
🎯 What You'll Learn
- Compare the Speed of Light in Glass (Fiber) vs Air (Microwave)
- Analyze Kernel Bypass Networking (DPDK / Solarflare)
- Deconstruct a Grid Trading Strategy (Mean Reversion)
- Calculate the Latency of Serialization (Protobuf vs SBE)
- Audit a Colocation Cage Power & Cooling setup
📚 Prerequisites
Before this lesson, you should understand:
Introduction
In the time it takes you to blink (300ms), an HFT algorithm has traded 10,000 times. The constraint is no longer human reaction time. The constraint is Physics.
- The Medium: Light travels 30% slower in Fiber (Glass) than in Air.
- The OS: The Linux Kernel adds 20 microseconds of overhead.
- The CPU: An L3 Cache miss costs 40 nanoseconds.
This lesson explores how we engineer around the limitations of the physical universe.
The Physics: Speed of Light (Glass vs Air)
Chicago (Futures) to New Jersey (Equities) is roughly 1200km.
- Fiber (Glass): . Speed is . Latency .
- Microwave (Air): . Speed is . Latency .
Optimization: HFT firms build microwave towers in a straight line (Great Circle path) to beat the fiber cables buried along curved highways. Result: If you use fiber, you see the price change 2ms after the microwave traders have already bought everything.
Deep Dive: Kernel Bypass (Solarflare / DPDK)
Standard Linux Networking is slow:
Wire -> NIC -> Driver -> Kernel (Interrupt) -> Copy to User Space -> Application.
Total: ~10-20 Microseconds.
The Solution: Kernel Bypass.
We map the Network Interface Card (NIC) memory directly into the Application’s RAM.
Wire -> NIC -> Application.
Total: ~1 Microsecond.
Physics:
This requires specialized libraries (OpenOnload, DPDK). socket(AF_INET, SOCK_STREAM) is replaced by direct memory polling.
Strategy: Grid Trading (Capturing Volatility)
HFTs love volatility. They don’t predict direction; they predict reversion.
The Algorithm:
- Current Price: $100.
- Place Buy Limit orders at 99.80, $99.70.
- Place Sell Limit orders at 100.20, $100.30.
Scenario: Price dips to 100.30 (fills 3 sells). Result: You bought low and sold high automatically. You profited from the “Noise” without knowing the trend.
Code: Kernel Bypass Concept
How does a “Busy Spin” loop replace an Interrupt?
# Conceptual pseudo-code for Kernel Bypass Polling
class NIC:
def poll_memory(self):
# Read a specific memory address mapped to the hardware ring buffer
# This bypasses the OS 100%
if memory[0x1234] == NEW_PACKET:
return parse_packet(memory[0x1234])
return None
nic = NIC()
while True:
# 1. Busy Spin (Consumes 100% CPU Core)
# Why? Because "sleep()" costs 10 microseconds to wake up.
# We cannot afford to sleep.
packet = nic.poll_memory()
if packet:
process(packet)
Practice Exercises
Exercise 1: Light Speed Math (Beginner)
Scenario: Distance 100km. Task: Calculate One-Way Latency in Fiber () vs Air (). (Fiber: 500us. Air: 333us. Advantage: 167us).
Exercise 2: Grid Trap (Intermediate)
Scenario: You have a Grid Strategy active. Event: Price crashes from 90 and stays there. Task: What is your P&L? (You bought all the way down, and now hold a bag of inventory at avg price $95. Huge paper loss).
Exercise 3: CPU Isolation (Advanced)
Task: Use isolcpus in GRUB to remove a core from the Linux Scheduler.
Run a busy-spin loop on that core. Measure the “Jitter” (Variance in loop time). It should be zero.
Knowledge Check
- Why is Microwave faster than Fiber?
- What does “Kernel Bypass” actually bypass?
- Why do HFT algorithms “busy spin” instead of sleep?
- How does Grid Trading fail?
- What is the “Great Circle Path”?
Answers
- Refractive Index. Light moves slower in dense glass than in sparse air.
- The OS Stack. No interrupts, no context switches, no buffer copies.
- Wake-up Latency. The OS scheduler takes microseconds to wake a sleeping thread. Polling is instant.
- Trending Markets. If price moves in one direction without bouncing, you accumulate infinite losing inventory.
- Geodesic. The shortest line between two points on a sphere (Earth).
Summary
- Physics: Air > Glass.
- Networking: Bypass > Kernel.
- Strategy: Speed enables Capture.
Questions about this lesson? Working on related infrastructure?
Let's discuss