Skip to content
LeetQuant
QD11 Quant Developer Interview Preparation

QD11 · Quant Developer Interview Preparation · Lesson 4 of 4

System Design Interviews

How a trading-firm system design interview runs, and a full worked design of a market-data distribution system with capacity numbers, components, failure handling and the trade-offs you will be questioned on.

20 min

How the interview runs

A design round lasts 45–60 minutes and starts with something deliberately vague: "design the system that gets market data to our strategies", "design an order gateway", "design a tick-data store". Trading firms differ from web companies in what they probe: latency and its variance, correctness under message loss, determinism and replay, and failure modes during the open, more than horizontal scale to millions of users.

A structure that works, with rough timings:

PhaseMinutesWhat you produce
Requirements5–8Functional scope, latency target, throughput, consumers, failure tolerance
Numbers5Peak messages per second, bytes, bandwidth, per-message time budget
High-level design10Boxes and arrows, data flow, where state lives
Deep dives15–20The two or three hardest parts, chosen with the interviewer
Failures and operations5–10Loss, crashes, slow consumers, monitoring, replay

Habits the interviewer is looking for: you ask before assuming, you compute numbers and let them drive the design, you state trade-offs as choices ("I would use X because of Y, at the cost of Z"), and you change the design when the interviewer adds a constraint rather than defending it.

The numbers below are stated assumptions for the exercise, chosen to be the right order of magnitude; in the interview say they are assumptions and ask whether they are reasonable.

Worked example

Worked example, part 1: requirements and numbers

"Design the system that takes market data from exchanges and delivers it to our trading strategies."

Show solution

Questions to ask (and the answers we will assume).

  • Which data? Equities, direct feeds from about 15 venues, full depth (order-by-order where available).
  • Who consumes it? About 30 strategy processes on each of 20 servers in the same data centre, plus a capture system for research and replay.
  • Latency target? Strategies on the same host as the feed handler need tick-to-strategy in single-digit microseconds; other hosts can tolerate tens of microseconds.
  • What must never happen? A strategy trading on a book that is silently wrong (for example after a lost packet).

Capacity, assuming a peak of 5 million messages per second across all venues and 40 bytes per message on the wire:

  • Payload: 5×106×40=2005 \times 10^{6} \times 40 = 200 MB/s =1.6= 1.6 Gbit/s.
  • Exchanges pack messages into UDP packets of about 1400 bytes: 3535 messages per packet, about 143,000143{,}000 packets per second. Ethernet, IP and UDP headers add about 42 bytes per packet, 66 MB/s, so about 1.651.65 Gbit/s in total.
  • Bursts: averages hide microbursts. If a 1 ms burst runs at five times the peak-second average, that is about 8.28.2 Gbit/s, close to a 10 GbE link's capacity. So: 10 GbE at minimum, 25 GbE for headroom, and NIC and socket buffers sized for bursts, not averages.
  • Time budget: 109/(5×106)=20010^{9} / (5 \times 10^{6}) = 200 ns per message if one core handled everything. That is too tight for parsing plus book building plus publishing at peak, so the design must shard across cores (by venue, then by symbol range).
  • Internal fan-out: normalised messages of 64 bytes (one cache line) at peak are 320320 MB/s ≈2.6\approx 2.6 Gbit/s. Sending a TCP copy to each of 20 hosts would be 5151 Gbit/s; multicast sends it once.
  • Capture: if the day averages 20% of peak over 6.5 hours (23,400 s), raw capture is 0.2×200 MB/s×23,400 s≈9360.2 \times 200 \text{ MB/s} \times 23{,}400 \text{ s} \approx 936 GB per day, about a terabyte before compression.

Each number has a design consequence: bursts set the link and buffer sizes; 200 ns per message forces sharding; fan-out bandwidth forces multicast; capture volume sets storage and compression.

Worked example, part 2: the design

Data flow.

  1. Exchange A and B feeds (each venue publishes the same data on two multicast lines) arrive at feed handler hosts, one or more per venue.
  2. The feed handler receives packets with kernel bypass (the NIC delivers into user-space memory, avoiding system calls and interrupts), arbitrates A/B (takes whichever copy of each sequence number arrives first, drops the duplicate), checks sequence numbers for gaps, decodes the venue's binary protocol, and builds the book per symbol. One busy-polling thread per venue or per symbol shard, pinned to an isolated core.
  3. Normalised updates go two ways:
    • Same host: a single-producer, multi-consumer shared-memory ring buffer. The writer never waits for readers; each reader keeps its own read position.
    • Other hosts: re-published on internal multicast, one group per venue or symbol shard so consumers subscribe only to what they need.
  4. Strategy processes read from the ring or an internal-multicast subscriber, which maintains a local copy of the books it needs.
  5. A capture process records raw packets with hardware timestamps to local disk and later to a central store, for replay and research.
  6. Recovery service: per venue, the exchange's snapshot and retransmission channels are used to rebuild a book after a gap.

Sizing the ring. 2222^{22} slots of 64 bytes is 256 MiB and holds about 222/(5×106)≈0.842^{22} / (5 \times 10^{6}) \approx 0.84 s of peak traffic. A reader that falls more than one ring behind has lost data: it detects this because each slot carries a sequence number, and it must resynchronise (from a snapshot published by the handler) rather than read overwritten slots.

Why these choices, stated as trade-offs.

DecisionChosenAlternativeWhy
Transport off-hostUDP multicastTCP per consumerOne send regardless of consumer count, and no head-of-line blocking; cost: loss must be handled by sequence numbers and recovery
Transport on-hostShared-memory ringSockets or a message brokerTens of nanoseconds, no copies through the kernel; cost: careful lock-free code and a slow-reader policy
Slow consumersWriter never blocks; slow readers detect overrun and resync, or subscribe to a conflated stream (latest state per symbol only)Back-pressureOne slow strategy must not delay everyone; cost: slow readers see gaps or coarser data
Book buildingIn the feed handler, onceIn every strategyDone once, consistently; cost: the handler is a critical component that must be redundant
ThreadsBusy-polling, pinned, isolated coresBlocking readsRemoves wake-up latency and jitter; cost: burns cores at 100%

Worked example, part 3: failures and operations

This is where most of the questioning happens. Prepare an answer for each:

  • Packet lost on one line. A/B arbitration fills it from the other line, invisibly.
  • Packet lost on both lines (a gap). Mark the affected books stale and publish that state, so strategies stop quoting those symbols. Request retransmission; if that fails or the gap is large, rebuild from a snapshot and replay buffered messages after the snapshot's sequence number. Never let a strategy trade on a book that is known to be incomplete.
  • Feed handler crash. Run a hot standby that consumes the same feeds and builds the same books but does not publish. Fail over on missed heartbeats. Consumers see a sequence reset and resynchronise from a snapshot. Discuss how failover is decided (a heartbeat timeout trades detection speed for false failovers).
  • Slow consumer. Detected by the lag between its read position and the writer's sequence. Alert, then move it to the conflated stream or restart it.
  • Clock and timestamps. Hardware timestamps on receive, clocks disciplined with PTP; record exchange timestamp, receive timestamp and publish timestamp on every message, so latency can be measured per hop.
  • Monitoring. Per venue: message rate, gap count, A/B line health, tick-to-publish latency percentiles (p50, p99, p99.9, max, not just the mean), ring lag per consumer.
  • Replay and determinism. The capture plus the same handler code must reproduce the exact book sequence. This is how bugs from the open are debugged and how strategies are tested.

If the question is an order gateway instead

The same method applies with different emphasis. Requirements: risk checks (order size, notional, position, price collars, message rate) before anything leaves; exchange session management (logon, heartbeats, sequence numbers, resend requests); mapping internal order ids to exchange ids. Numbers: orders per second and per-order risk-check budget. Key trade-offs: risk checks inline on the hot path (safe, adds latency) versus a separate pre-trade service; a kill switch that cancels all orders; what happens to open orders if the gateway or the session drops (exchange cancel-on-disconnect settings). The rate limiter from the timed coding sets is one small component of it.

Worked example

handling a constraint change

Midway through, the interviewer says: "A new strategy runs in a different data centre 1 ms away and needs the same data. Your internal multicast does not cross data centres. What changes?"

Show solution

Reason from the requirement. At 1 ms of one-way network latency, saving microseconds in the transport is irrelevant; reliability and bandwidth across the link matter. So it is acceptable to use a different, slower transport for this consumer.

Design. A bridge process subscribes to the internal multicast groups the remote strategy needs and forwards them over a reliable connection (TCP, or UDP with sequence numbers and retransmission) to a matching bridge that re-publishes locally in the remote data centre.

Bandwidth. The full normalised stream at peak is about 2.6 Gbit/s; if the link is smaller, send only the needed symbols or a conflated stream (latest state per symbol every few milliseconds), which bounds bandwidth regardless of burst size.

Failure behaviour. On a link drop the remote books become stale and the bridge resynchronises from snapshots on reconnect, the same mechanism as a gap.

Notice the shape of the answer: restate what the new constraint changes, reuse existing mechanisms (snapshots, conflation, sequence numbers), and give the new number.

Knowledge check

Market data peaks at 5 million messages per second. Roughly what is the per-message time budget if a single core does all the work, and what does it imply?

Knowledge check

The feed handler detects a sequence gap on both the A and B lines for one venue. What should happen first?

Knowledge check

One strategy on a host reads the shared-memory ring too slowly. Which policy keeps the other 29 strategies unaffected?

Key takeaways

  • Spend the first ten minutes on requirements and numbers, and let each number drive a decision (link size, sharding, multicast, storage).
  • Trading-system design is dominated by latency variance, loss handling, determinism and replay.
  • The market-data pattern: A/B arbitration, sequence-gap detection, book building once in the handler, a shared-memory ring on-host, multicast off-host, snapshots for recovery, capture for replay.
  • Never let a strategy trade on a book known to be incomplete: publish staleness explicitly.
  • State trade-offs as "X because Y, at the cost of Z", and adapt the design when the interviewer adds a constraint.

Finished reading?

Answer the 3 knowledge checks to complete this lesson (0 done).