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.

Beginner 45 min read Expert Version →

🎯 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

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): RefractiveIndex1.5Refractive Index \approx 1.5. Speed is c1.5\frac{c}{1.5}. Latency 6ms\approx 6ms.
  • Microwave (Air): RefractiveIndex1.0003Refractive Index \approx 1.0003. Speed is c\approx c. Latency 4ms\approx 4ms.

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:

  1. Current Price: $100.
  2. Place Buy Limit orders at 99.90,99.90, 99.80, $99.70.
  3. Place Sell Limit orders at 100.10,100.10, 100.20, $100.30.

Scenario: Price dips to 99.70(fills3buys),thenbouncesto99.70 (fills 3 buys), then bounces 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 (200,000km/s200,000 km/s) vs Air (300,000km/s300,000 km/s). (Fiber: 500us. Air: 333us. Advantage: 167us).

Exercise 2: Grid Trap (Intermediate)

Scenario: You have a Grid Strategy active. Event: Price crashes from 100to100 to 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

  1. Why is Microwave faster than Fiber?
  2. What does “Kernel Bypass” actually bypass?
  3. Why do HFT algorithms “busy spin” instead of sleep?
  4. How does Grid Trading fail?
  5. What is the “Great Circle Path”?
Answers
  1. Refractive Index. Light moves slower in dense glass than in sparse air.
  2. The OS Stack. No interrupts, no context switches, no buffer copies.
  3. Wake-up Latency. The OS scheduler takes microseconds to wake a sleeping thread. Polling is instant.
  4. Trending Markets. If price moves in one direction without bouncing, you accumulate infinite losing inventory.
  5. 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