Quant developer HFT course · Module 7: The network
Drill: the network
Network questions often begin with "why" and end with "what would you do". Explain the protocol behaviour, then the evidence, then the fix.
Prompt 1: Two protocols
The interviewer says
Why is market data UDP multicast and order entry TCP?
Before you answer
Question · choose every correct option
Which reasons are correct? Choose all that apply.
One-to-many timely data versus one-to-one complete instructions; neither protocol is encrypted by itself.
Answers that lose the point
UDP is faster.
Only half the story; the reasons are fan-out, freshness and reliability needs.
A strong answer
Market data is one-to-many and loses value in milliseconds. Multicast lets the network deliver each packet to every subscriber at once, and UDP never holds back new data while waiting for a lost packet to be retransmitted. Loss is handled by sequence numbers, redundant A and B feeds and recovery services.
Orders are one-to-one and every message must arrive, once and in order: a cancel must not overtake its order. TCP gives that, and on dedicated low-loss links its cost in normal operation is close to UDP's. The exchange's session protocol adds its own sequencing on top.
Prompt 2: The gap
The interviewer says
Your feed handler sees sequence number 5002 after 5000. What do you do?
Before you answer
Question · choose every correct option
Which steps are right? Choose all that apply.
A missing message leaves the book wrong; recovery must make it right and strategies must know in the meantime.
Answers that lose the point
Ignore it, the next update will fix things.
A missed delete leaves a phantom order in the book indefinitely.
A strong answer
First, arbitration: 5001 may arrive on the B feed, or slightly reordered, so I would wait briefly and buffer 5002 onwards. If it does not arrive, the books on that channel may be wrong, so I would mark them stale and tell strategies not to trade on them.
Then recover: request 5001 from the exchange's retransmission service and apply the buffered packets after it, or, if that is unavailable or the gap is large, rebuild from a snapshot and replay buffered packets newer than the snapshot's sequence number. Gaps and recoveries go into monitoring, because frequent gaps point at drops on our side.
Prompt 3: Gaps at the open
The interviewer says
The exchange says it lost nothing, but we see gaps at the open. Where do you look?
Before you answer
Question · choose every correct option
Which are plausible? Choose all that apply.
Bursts overflow some queue on our side; counters at each layer show which.
Answers that lose the point
Increase all the buffers.
May help, but without the counters you do not know which buffer, or whether the reader is simply too slow.
A strong answer
Bursts at the open can reach line rate for short periods, and every queue on our side must absorb them. I would check the switch port counters, ethtool statistics for NIC ring drops, and netstat or /proc/net/udp for socket buffer drops, alongside our own ring counters.
Then fix the layer that drops: larger NIC rings and socket buffers, a handler that keeps up with the burst rate with its work on the receive thread kept minimal, kernel bypass with a dedicated polling core on the card's socket, and measuring rates at millisecond resolution rather than per second.
Prompt 4: Slow orders
The interviewer says
Orders sometimes leave tens of milliseconds late, always just after another small order. Why?
Before you answer
Question · choose every correct option
What could explain it? Choose all that apply.
Nagle plus delayed acks is the classic cause of tens-of-milliseconds delays on small back-to-back writes.
Answers that lose the point
The network is congested.
The pattern, always after another small order, points at Nagle.
A strong answer
That pattern is Nagle's algorithm: with data still unacknowledged, TCP holds a new small write back to combine it with later data. The exchange side may delay its acknowledgement, so the hold lasts tens of milliseconds.
I would set TCP_NODELAY on the order connection and make sure each order goes out in a single send call, then confirm with packet captures and hardware transmit timestamps.
Prompt 5: Faster than the kernel
The interviewer says
We have tuned the kernel path. How do we go faster?
Before you answer
Question · choose every correct option
Which options belong in the answer? Choose all that apply.
Exchanges deliver over Ethernet and IP; RDMA is for traffic between your own servers.
Answers that lose the point
Use RDMA.
The wrong tool for exchange connectivity.
A strong answer
Kernel bypass next: Onload gives most of the benefit behind the existing socket code, and ef_vi or DPDK give raw ring access if we handle the protocol headers ourselves. A dedicated thread on an isolated core local to the card polls the receive ring, so there are no interrupts, system calls or copies.
Beyond that, the fastest reactions move into hardware: an FPGA on the card that parses the feed and fires pre-armed orders under limits set by software. Each step costs more development effort and flexibility, so I would choose by how much latency the strategy is actually worth.
After the drill
Network answers work best when you can follow a packet: from the exchange through the switch and the card, through or around the kernel, into the handler and back out as an order. Module 8 is about measuring that journey and finding where the time went.