The Physics of Data Feeds: Multicast & Arbitration

Why TCP is too slow. The physics of UDP Multicast, A/B Arbitration, and Zero-Copy Serialization (SBE).

Intermediate 45 min read Expert Version →

🎯 What You'll Learn

  • Deconstruct UDP Multicast (Physics of Fan-out)
  • Analyze A/B Arbitration (Gap Filling)
  • Trace a Packet: NIC -> Kernel -> User Space (Zero Copy)
  • Calculate the Serialization Cost of JSON vs SBE
  • Audit a Market Data Handler for Sequence Gaps

📚 Prerequisites

Before this lesson, you should understand:

Introduction

If you are using WebSocket for market data, you are already 50 milliseconds behind. Real exchanges do not use TCP. They use UDP Multicast. They shout prices into the void, and your hardware must catch them. If you miss a packet, it is gone forever.

This lesson explores the ruthless physics of Direct Market Access (DMA) feeds.


The Physics: Multicast (UDP)

TCP requires a Handshake (SYN/ACK). It guarantees order. It handles retransmission. This is too slow. Exchange Engines broadcast data like a Radio Tower. One Sender -> Infinity Receivers.

The Physics:

  • TCP: Exchange must send copy to User A, then User B, then User C. (Serialization Delay).
  • Multicast: Exchange sends one packet to the Switch. The Switch uses hardware circuits to copy the electrons to Ports A, B, and C simultaneously.
  • Latency: O(1)O(1) regardless of user count.

Deep Dive: A/B Feed Arbitration

UDP is “Unreliable”. Packets drop. To solve this, exchanges broadcast Two Identical Feeds (Feed A and Feed B) on different physical cables.

The Physics of Arbitration: Your FPGA/NIC listens to both wires.

  • Packet 1 arrives on A. Pass to engine.
  • Packet 1 arrives on B. Discard.
  • Packet 2 is dropped on A.
  • Packet 2 arrives on B. Pass to engine.

Result: You only lose data if both cables fail at the exact same microsecond. A “Perfect Feed” is synthesized from two imperfect physical streams.


Strategy: Serialization (JSON vs SBE)

Parsing text is slow. {"price": 100.5} requires scanning for quotes, colons, and parsing ASCII to Float. Cost: ~2 microseconds.

SBE (Simple Binary Encoding): Data is laid out in memory exactly as it looks on the wire.

  • Price is at Offset 0 (8 bytes).
  • Qty is at Offset 8 (8 bytes). Parsing: struct->price. Zero CPU cycles. A memory read. Cost: ~5 nanoseconds.

Architecture: Kernel Bypass (Solarflare)

The OS Kernel is a “Middleman”. Standard Linux: NIC -> Ring Buffer -> IRQ -> Kernel Copy -> User Copy. HFT (Onload/DPDK): NIC -> User Space Memory. The Kernel is completely bypassed. The application reads directly from the network card’s RAM.


Code: Gap Detection (Python Prototype)

Real HFT is C++, but the logic is:

class Arbitrator:
    def __init__(self):
        self.next_seq = 0
        
    def on_packet(self, packet, source_id): # source_id = 'A' or 'B'
        seq = packet.sequence_number
        
        if seq == self.next_seq:
            self.process(packet)
            self.next_seq += 1
        elif seq > self.next_seq:
            # GAP DETECTED!
            # We missed a packet. Buffer this one. Check the other feed.
            self.buffer[seq] = packet
            print(f"Gap on Feed {source_id}! Waiting for other feed.")
        else:
            # Old packet (we already processed it from the other feed)
            pass # Drop it

Practice Exercises

Exercise 1: The Microburst (Beginner)

Scenario: Exchange sends 10,000 packets in 1ms. Result: Your User Space buffer is full. Packets are dropped at the NIC. Solution: Larger Ring Buffers (Hardware) or Faster Consumption (Pin thread to core).

Exercise 2: The Parsing Tax (Intermediate)

Scenario: Parse 1 Million JSON messages vs 1 Million Binary messages. JSON: 2 seconds. Binary: 5 milliseconds. Lesson: Never use JSON for hot paths.

Exercise 3: Sequence Repair (Advanced)

Scenario: Both Feed A and Feed B miss Packet 105. Action: You initiate a TCP Replay Request to the exchange. Latency: 50ms penalty. You are out of the market until gap is filled.


Knowledge Check

  1. Why do exchanges use Multicast instead of TCP?
  2. What is A/B Arbitration?
  3. Why is JSON bad for HFT?
  4. What is Kernel Bypass?
  5. What happens when a UDP packet is dropped?
Answers
  1. Fairness & Speed. Everyone gets data at the same time; One send = Infinite receivers.
  2. Redundancy. Listening to two identical feeds to fill gaps in real-time.
  3. CPU Overhead. ASCII parsing consumes critical clock cycles.
  4. Zero Copy. Application reads directly from NIC memory, skipping OS.
  5. Gone. It is not retransmitted automatically. You must request it manually.

Summary

  • UDP: Fire and Forget.
  • Arbitration: Two ears are better than one.
  • SBE: Zero-copy parsing.


Pro Version: See the full research: First Principles of Trading Infrastructure

Questions about this lesson? Working on related infrastructure?

Let's discuss