System Design: High-Frequency Trading Platform (Walnut Quant: Tick-to-Trade in Microseconds, Kernel Bypass, Linux Tuning, FPGA, Microwave, Pre-Trade Risk)
We design the trading platform of a high-frequency trading firm. Our firm is called Walnut Quant, and it is made up for this post. It keeps buy and sell prices in thousands of US stocks all day, and changes them within a few microseconds of any news.
As in any system design interview, every number here is our own planning assumption. The design is our own too. Rules and real events are marked with their year.
Code timings were measured on a laptop and are marked as such. All times are US Eastern time.
How to read this post. It takes about 85 minutes in full, so it is built to be read in parts:
1. Requirements
1.1 What we are building
Walnut Quant is a market maker. A market maker keeps a buy price and a sell price in the book all day, so other people can always trade.
It earns the small gap between the two prices. It loses money when the price moves before it can change its quotes.
So speed decides profit and loss. If the price of an index future in Chicago falls, our quotes in New Jersey are wrong until we change them. The firm that reacts first trades against the wrong quotes of all slower firms.
Walnut Quant does five jobs:
- It reads market data from four stock exchanges in New Jersey, and the price of index futures from Chicago.
- It keeps quotes in 3,000 US stocks and ETFs. An ETF is a fund that trades like a stock. One example is a fund that holds every stock in an index.
- It reacts within microseconds. From a market data packet in to an order out takes about 2 µs in software. For a few cases, special hardware takes under 100 ns.
- It checks every order before it leaves. Every order passes the limit checks, even when the strategy code is wrong.
- It records everything. Every packet in and out is kept with an exact time. It is used for research, for latency reports and for regulators.
To keep the design small, we assume all four exchanges match orders in one New Jersey data center. In the real US market they sit in different buildings, tens of km apart.
A real firm puts servers in each building. It links them by microwave or short fiber.
The story takes place on Thursday 3 December 2026, the same day as the stock exchange post:
- 06:30. Each strategy server measures its own pauses. The largest pause on any trading core is 4 µs, under the 10 µs limit.
- 06:45. The start-of-day check finds that strategy server QT5 runs build 7740, not today's build 7741. It refuses to let QT5 trade. Marcus is the engineer on call. He installs build 7741 on QT5, and at 06:58 every check passes.
- 09:30:00. The market opens. Walnut Quant quotes 3,000 symbols on four exchanges.
- 10:14:02. A large sale in Chicago drops the WIX index future by 0.2% in one millisecond. Our relay in Chicago sends the new price by microwave. The price reaches New Jersey 4.0 ms later. Within 100 ns, special hardware starts canceling 12 bids on four exchanges, and all 12 cancels leave within about 0.3 µs. The bids are in WIDX and two other ETFs on the same index.
- 10:14:02.0065. Firms that use fiber see the price 2.5 ms later than we do.
- 11:20. Heavy rain over Pennsylvania weakens the microwave link. The Chicago price now comes by fiber, which is 2.5 ms slower. So the strategy widens its quotes in index-linked symbols. At 11:48 the link is back.
- 12:40:10. On Walnut Exchange's market data channel WX-3, line A loses 58 packets and line B loses 1 other. Then both lines lose the same one packet. The 40 symbols on that channel are marked "not sure" for 0.8 ms. In that time, Walnut Quant sends no new quote in them, and its resting quotes stay.
- 13:52:07. Nora is a quant researcher. She released parameter version v318 that morning. On strategy server QT3, v318 makes the ETF strategy send ten times its usual order changes. This shows only when WIDX's spread, the gap between best bid and best offer, stays under one cent for minutes. No tested day had that. The rate check refuses every order change over 800 a second.
- 13:52:08. The Risk service sees the refusals and QT3's growing position. It presses the kill switch for that strategy on QT3. 1,140 resting orders are canceled.
- 14:20. Grace, the risk officer, approves a return to version v317. QT3 trades again.
- 16:20. Our own record of every fill matches the four exchanges' copies. The difference is zero.
- 18:00. The day's capture is stored: about 190 GB of packets. Overnight, Nora replays the day to test a fixed v318.
The hard part is to react in a few microseconds every time, not only on average. At the same time, the firm must never send an order it cannot afford. One pause of 100 µs at the wrong moment costs more than a slow average.
1.2 Words we use
Words used in only one place are explained there. Each word below is used all through the post.
Trading
| Word | Meaning |
|---|---|
| Market maker | A firm that keeps a buy price and a sell price in the book all day, and earns the gap between them. |
| Quote | Our resting buy order and sell order in one symbol, on one exchange. |
| Bid, offer | A buy order's price, and a sell order's price. |
| Order book | For one symbol on one exchange, every resting buy and sell order, sorted by price. |
| Top of book | The best bid and the best offer, with their sizes. |
| Index future | A contract on the value of a stock index, traded in Chicago. It often moves a few milliseconds before the stocks. |
| Signal | A piece of news the strategy reacts to, such as the futures price falling. |
| Strategy | The program that decides our quotes. Server QT3 runs two: one for ETFs and one for stocks. |
| Position | How many shares of a symbol we own after our fills. A negative position means we owe shares. |
| Spread | The gap between a bid and an offer. A wider spread makes our quotes safer. But they fill less often. |
| NBBO | The national best bid and offer: the best bid and the best offer across all four exchanges together. |
| Lock, cross | A quote locks the market when it equals another exchange's best price on the other side. It crosses the market when it goes past that price. US rules ban showing either. |
| Arbitrage | Trading on a price that moves first in one market, before a linked market follows. Our Chicago signal is one kind, often called latency arbitrage. |
| Index-linked symbol | A stock or ETF whose price follows an index, so it moves when the index future moves. |
| Arm, disarm | An armed server may send orders. A disarmed one may not. |
| Parameters | The numbers a strategy runs with, such as how wide to quote. A set of them has a version, such as v318. |
| Fill | A report from the exchange that our order traded. |
| Drop copy | A second copy of every fill, sent by the exchange to our Risk service. |
Speed
| Word | Meaning |
|---|---|
| µs, ns | A microsecond is a millionth of a second. A nanosecond is a thousandth of a microsecond. |
| Tick-to-trade | The time from a market data packet entering our cage to our order leaving it, measured on the cables. |
| Latency | How long one thing takes. p50 is the time that half of all cases beat. p99 and p99.9 are the times that 99% and 99.9% of cases beat. |
| Jitter | How much the latency changes from one case to the next. A rare long pause is jitter. |
Trading networks
These are the physical paths between the exchanges and our servers. A reader who has never seen a trading data center can read this table first.
| Word | Meaning |
|---|---|
| Colocation | Renting space for our servers inside the exchange's own data center. Then the cable to the exchange is tens of meters long, not kilometers. |
| Cage | Our locked area of racks inside that data center. |
| Cross-connect | The cable from our cage to the exchange's network, inside that data center. Every member gets the same length. |
| Fiber | Glass cable that carries data as light. Light in glass covers about 200 m in 1 µs. |
| Microwave link | A chain of radio towers about 50 km apart. Each tower has dishes that pass the signal to the next one. Radio in air is faster than light in glass. |
| Rain fade | Heavy rain absorbs the radio signal, so a microwave link loses packets until the rain passes. |
| Layer-1 switch | A network switch that copies the electrical signal to many ports at once, in about 4 ns. A normal switch reads each packet first, which takes hundreds of nanoseconds. |
| Network tap | A device in the cable that copies every packet to a second cable, without touching the original. |
| PTP grandmaster | The master clock on our network, fed by GPS. PTP stands for Precision Time Protocol. It keeps every other clock within well under a microsecond of the master clock. |
| Drop copy, cancel-on-disconnect | Two exchange services. Drop copy sends a second copy of every fill. Cancel-on-disconnect cancels all our orders on a session if its heartbeats stop. |
Inside the server
| Word | Meaning |
|---|---|
| Core | One processor inside the CPU. It runs one thread at a time. |
| Pinned thread | A thread that runs on one chosen core and never moves. |
| Isolated core | A core that Linux keeps free of its own work, so our thread runs alone on it. |
| Busy polling | A thread checks for new data in a tight loop, instead of sleeping until woken. |
| Ring | A fixed-size list in memory that one thread writes and another reads, in a circle. |
| Shared memory | Memory that two programs on one server both see. Here it is a file in /dev/shm, Linux's folder kept in RAM. Both programs map this file into their memory. |
| Memory-mapped file | A file that a program reads and writes as if it were memory. The kernel copies the changes to the file in the background. |
| Cache line | The block the CPU moves as one unit between memory and its caches: 64 bytes on the x86 servers here. |
| Kernel bypass | The network card writes packets straight into our program's memory. Our program hands orders straight to the card. Neither step goes through the kernel. |
| PCIe | The bus that connects the network card to the CPU and memory. |
| FPGA | A chip whose circuits we program, so a task runs in hardware in nanoseconds. FPGA stands for field-programmable gate array. |
Linux, in plain words
Most engineers use Linux without seeing its inside. These are the parts this post changes, and what each one normally does.
| Word | Meaning |
|---|---|
| Operating system, kernel | The operating system shares one machine among many programs. Its kernel is the part with full control of the hardware. Here the kernel is Linux. |
| User space | Where ordinary programs run, such as our trading program. They ask the kernel for help through system calls. |
| System call | A request from a program to the kernel, such as "read this socket". Each one costs from about 100 ns to several microseconds. |
| Socket | The normal way a program sends and receives network data, through the kernel. |
| Interrupt | A signal from a device, such as the network card. It makes a core stop its work at once and run kernel code. |
| Scheduler | The part of the kernel that decides which thread runs on which core, and moves threads around. |
| Timer tick | An interrupt the kernel gives each core 250 to 1,000 times a second. It keeps time and switches threads. |
| Sleep state | A power-saving mode an idle core drops into. Waking up from a deep one takes up to about 100 µs. |
| Page, page fault | Memory is handed out in pages, usually 4 KB. A page fault is the pause when a program first touches a page the kernel has not prepared. |
| TLB | The CPU's small table of recent page lookups. A miss costs about 100 ns. Bigger pages mean fewer misses. |
| Huge page | A 2 MB page instead of 4 KB, so the TLB covers 512 times more memory. |
| Boot line | Settings given to the kernel when the machine starts, such as which cores to leave alone. |
| eBPF | A way to load a small program into the running kernel. The kernel first checks that the program is safe. Then the kernel runs the program when a chosen event happens, such as a packet arriving. |
| XDP, AF_XDP | XDP runs an eBPF program in the network driver, before the rest of the kernel sees a packet. AF_XDP uses it to hand packets straight to a program. |
| ef_vi, Onload, DPDK | Kernel bypass libraries. The first two come from one network card maker. DPDK is open source and works with many cards. |
Market data
| Word | Meaning |
|---|---|
| Feed | The exchange's stream of every change to every book, sent by multicast. Each message adds, changes or removes one order. |
| ITCH, OUCH | Nasdaq's binary formats for market data and for orders. Other exchanges use similar ones. |
| Multicast | One network packet sent once and copied by the network to every subscriber. |
| Line A, line B | Two copies of the same feed on two separate networks, so a packet lost on one is usually on the other. |
| Channel | One part of a feed, carrying a fixed group of symbols. |
| Stock locate | A number from 1 to about 12,000 that an exchange gives each symbol for the day. |
| Re-request server | The exchange's server that sends again the packets a member lost. |
| Snapshot | A copy of every book on a channel at one moment. It carries the sequence number of the last message it includes. A server that starts late loads it, then follows the feed. |
Other words
| Word | Meaning |
|---|---|
| TCP, UDP | Two ways to send data over a network. TCP is a connection that resends lost packets and keeps them in order. UDP sends single packets with no resend, which is faster and suits multicast. |
| Header | The delivery details at the front of a packet, such as the address and port it is going to. |
| Heartbeat | A small message sent every second on a session, to show the other side it is still alive. |
| Hyperthread | A second thread that shares one physical core. The two slow each other down, so we turn it off. |
| Hash | A short fingerprint of a file. Any change to the file gives a different hash. |
| NTP | The usual way computers set their clocks over a network. On a local network it is accurate to tens of microseconds at best. |
| Object storage | Cheap cloud storage for large files, written once and read many times. |
| SEC, FINRA | The SEC is the US markets regulator. FINRA is the regulator of US brokers and trading firms. |
IDs in this post
Every ID below is made up for the story.
| ID | What it names | Example |
|---|---|---|
| WIDX, HRBX | Stock and ETF symbols | WIDX, an ETF on an index; HRBX, a stock |
| WIX | An index future in Chicago | The future on WIDX's index |
| QT1 to QT8 | A strategy server | QT3 runs the ETF strategy for WIDX |
| 7741 | A build number of our trading code | Today's build |
| v318 | A parameter version | Nora's change on 3 December |
| WX-3 | A market data channel | Walnut Exchange's channel 3 |
| WQ-S05 | One of our sessions at an exchange | QT3's session at Walnut Exchange |
| QT3-0081234 | Our order ID | One of QT3's WIDX quotes |
1.3 Every kind of event
The story follows a few events. Walnut Quant handles many more. Each row names the part that handles it.
| Kind | What it is | How big or how often | Which part handles it | Outside party that takes part |
|---|---|---|---|---|
| Market data | Every change to every book on four stock exchanges | Up to 4 million messages a second | Feed handlers | The four exchanges |
| Futures prices | Changes to index futures in Chicago | Thousands a second | The Chicago relay, the microwave link and the Signal receiver | The futures exchange, the microwave operator |
| New quote or change | Our order to add, change or cancel a quote | Up to 20,000 a second across the firm | Strategy engines and Order gateways | The four exchanges |
| Fill | One of our orders trades | Hundreds of thousands a day | Order gateways, the Risk service | The exchanges |
| Drop copy | The exchange's second copy of each fill | The same | The Risk service | The exchanges |
| Gap | Packets lost on both feed lines | A few a day | Feed handlers and the re-request server | The exchange |
| Kill switch | Cancel every order of one strategy, server or the firm | A few a month | The Risk service and Order gateways | The exchanges cancel too, if our session drops |
| Release | New code or new parameters | Code weekly, parameters daily | The Release service and the start-of-day check | None |
| Capture | Every packet in and out, with its time | About 190 GB a day after compression | Network taps and the Capture appliance | None |
| Records | Every order and fill, for regulators | Every day | The Order store and the Reporting job | The Consolidated Audit Trail, CAT |
| Research | Replays of past days to test new parameters | Every night | The Backtest cluster and the Tick store | None |
1.4 Functional requirements
- Read market data. Read every feed of the four exchanges on both lines. Find and fill every gap.
- Keep the books. Keep the top of book for every symbol. Mark it "not sure" whenever a gap is open.
- Read the Chicago signal. Read the index futures prices by microwave, with fiber as backup.
- Quote. Add, change and cancel our quotes in 3,000 symbols on four exchanges.
- Check every order. Check size, price, position and rate limits before the order leaves the server.
- Stop everything fast. A kill switch per strategy, per server and for the whole firm.
- Release safely. Release new code and new parameters only after tests. Never run a mix of versions.
- Record and report. Record every packet and every order with exact times. Keep them for years.
- Research. Replay any past day through any version of the strategy.
Out of scope:
- the trading ideas themselves, which are each firm's secret;
- options, which later sections cover as a way to grow;
- hedging, which uses the same parts in Chicago. One example is selling WIX futures there against a WIDX position;
- the exchange's matching engine, which the stock exchange post covers.
1.5 Non-functional requirements
- Fast. Tick-to-trade under 3 µs at p99 in software. Under 100 ns on the FPGA path.
- Steady. No pause over 10 µs on a trading core during the trading day. The tail matters more than the average.
- Safe. No order leaves without passing the pre-trade checks. A kill switch stops a strategy within 1 second.
- Correct books. No quote is sent from a book with an open gap.
- Exact records. Every order and fill is recorded with a time accurate to 1 µs. The records match the exchanges' copies each day.
- Available. If a strategy server fails, the exchanges cancel its quotes within 1 second. Cancel-on-disconnect does this. No other server takes its symbols during the day.
1.6 The numbers
These are rough sums, the kind a candidate does at a whiteboard in a few minutes.
| Number | How we get it | Result | What it decides |
|---|---|---|---|
| Market data at peak | 4 exchanges × 1 million messages a second, the exchange's own planning peak | 4 million a second | One feed handler core per exchange feed, never shared |
| Time per message | 1 second ÷ 1 million messages on one feed | 1 µs | Parsing and the book update must take well under 1 µs. The strategy reads the latest book, not every message |
| Light in glass | About 200,000 km a second, so 200 m in 1 µs | 5 ns a meter | Servers go in the exchange's data center. A server 30 km away in an office is 150 µs away each way |
| Chicago to New Jersey | About 4.0 ms by microwave, about 6.5 ms by fiber, one way | 2.5 ms earlier | Rent microwave for the futures signal, and keep fiber as backup |
| Symbols per server | 3,000 symbols ÷ 8 strategy servers | 375 each | Each symbol has one owner, so its position lives in one place |
| Our orders | 20,000 a second at peak ÷ 8 servers ÷ 4 exchanges | About 625 a second per session | A rate limit of 800 a second per session, checked on every order |
| Top of every book | 12,000 stock locates × 64 bytes | 768 KB | An array indexed by stock locate fits in the CPU's cache |
| Capture | 4 exchanges × 3 billion messages a day × 64 bytes = 768 GB; compressed 4 to 1 | About 190 GB a day | Compressed files in object storage, not a database. Over 5 years, that is about 240 TB |
What these numbers tell us: the work per message is small, and one core can do it. The hard part is time.
Each microsecond spent on distance, kernel work or a pause is lost time. One 100 µs pause equals 50 reactions missed or made too late.
So the design moves our servers next to the exchange. It takes the kernel off the path and gives each job its own core.