Market data: multicast feeds, book building, snapshots, and the arithmetic of a busy open

A book is a snapshot plus increments applied in sequence order. Feeds are UDP multicast because retransmission is worse than loss, receive-side loss is usually your own buffers, and capacity is sized for the open, not the average.

Read the briefing
About 4 min to read 6 drills

What to remember

  1. Join the increment stream first, then apply the snapshot, then replay what you buffered. Any other order leaves the book subtly wrong — and subtly wrong books show up as bad fills, not as errors.
  2. Multicast A/B: take both, de-duplicate by sequence. Redundant streams cover single-path loss without asking anyone to retransmit into a live book.
  3. Receive loss is usually local: rmem_max, a slow consumer, or IRQ contention. UdpRcvbufErrors names it immediately. Blaming the network is the expensive detour.
  4. Size for the open and for news, not the mean. Peak message rates run an order of magnitude over average; buffers, threads and capture disk are dimensioned from the peak.
  5. Capture at line rate with hardware timestamps, and keep it. It is how venue disputes, latency regressions and audits are settled. Retention is a requirement, not an optimisation.

The big picture

Market data is a high-rate, loss-tolerant-by-design transport carrying state that must be reconstructed exactly. This topic covers why the transport looks the way it does, how a book is built and repaired, where loss actually comes from, and how capacity and capture are sized.

The mental model

The feed is a log you join in the middle. The snapshot tells you where the log was at some sequence; the increments move you forward from there. Everything hard is about joining, repairing and keeping up.

In depth

Transport: why UDP multicast

Exchanges fan out identical data to many subscribers, so multicast is the efficient shape, and UDP is chosen because a retransmission arriving late into a live book is worse than a gap you can detect and repair. Venues typically publish two redundant streams (A and B) over different paths; the receiver takes both and de-duplicates by sequence number, so a single-path loss is invisible. The network is part of your correctness surface: IGMP membership and querier behaviour, switch buffer depth, and NIC receive descriptors all decide whether you see every message.

Some venues also offer a TCP or websocket feed for convenience or for retail-scale consumers; it trades latency and burst tolerance for simplicity, and is usually the wrong choice for a market-making path.

Building the book

The correct join sequence is: subscribe to increments and start buffering, then request or await the snapshot, then apply the snapshot and replay buffered increments from the snapshot's sequence number. Doing it the other way round — snapshot first, then subscribe — leaves a hole for everything published in between. From then on, every increment must be applied in order and exactly once; a gap means the book is wrong and must be repaired (from the redundant stream, a recovery/replay channel, or a fresh snapshot) before it is trusted again.

Implementation notes that show experience: keep a per-instrument sequence, not just a per-stream one, when the protocol has both; handle the venue's explicit "book cleared" or trading-state messages rather than inferring; and make the decision "stop trading this instrument" automatic when its book is in a gapped state.

Where loss actually comes from

Almost always the last few metres. Socket receive buffer too small: net.core.rmem_max plus the application's SO_RCVBUF, visible as UdpRcvbufErrors in nstat//proc/net/snmp. A slow consumer: the thread that drains the socket is doing parsing or logging work it should hand off, so the buffer fills during bursts. IRQ or core contention: the receive queue's interrupt lands on a busy core, or the consumer is preempted. Then, and only then, the network: switch buffer exhaustion during a burst, or an IGMP problem dropping the group.

Instrument all four: per-stream gap counters, UdpRcvbufErrors and NIC drops, consumer queue depth, and last-message age. That set tells you which of the four it is without guessing.

Capacity, capture and the open

The open, the close and news events produce message rates an order of magnitude above the mean, and they are the moments your book must be right. Size receive buffers, ring descriptors, consumer threads and capture storage from the observed peak with headroom, and load-test with a replayed peak rather than average traffic. Then capture everything: line-rate packet capture with hardware timestamps, retained for the regulatory window and searchable by instrument, sequence and time. It is what makes latency regressions and venue disputes provable, and reconstructing an incident without it is guesswork with money attached.

Myths and facts

Myth: TCP would be safer for market data.

Fact: Head-of-line blocking and retransmission add unbounded latency to a live book; venues use UDP multicast with redundant streams precisely to avoid that.

Myth: Take the snapshot first, then subscribe.

Fact: That loses everything published in between. Subscribe and buffer first, then apply the snapshot and replay.

Myth: Gaps mean the exchange dropped data.

Fact: Usually it is your receive buffer, your consumer or your IRQ placement. Check UdpRcvbufErrors before writing to the venue.

Myth: Redundant A/B streams remove the need for gap handling.

Fact: They cover single-path loss. Correlated loss, local buffer overflow and venue-side gaps still happen, so recovery stays mandatory.

Myth: Capture is a nice-to-have.

Fact: It is the evidence layer for disputes, audits and regressions, and its retention is usually a compliance obligation.

How pros do it

  • Take both A and B streams and de-duplicate by sequence; alert on per-stream gaps and last-message age.
  • Join with increments-then-snapshot-then-replay, and make a gapped book automatically stop trading that instrument.
  • Raise rmem_max and set SO_RCVBUF explicitly; keep the socket-draining thread doing nothing but draining.
  • Size buffers, threads and capture from observed peak rates with headroom; load-test with replayed peak traffic.
  • Capture at line rate with hardware timestamps and retain it for the regulatory window.

Questions people ask

How big should the receive buffer be, and why am I still dropping?

Big enough to cover the largest burst your consumer can fall behind by — tens of megabytes is common for a busy feed — derived from measured burst size, and set with SO_RCVBUF as well as rmem_max, because the sysctl alone changes nothing for a socket that never asked. Then confirm UdpRcvbufErrors stays flat through an open. If it still climbs, the consumer is the problem, not the bucket.

How do I know my book is right?

Cross-check top-of-book against a second source or the venue's periodic snapshot, and reconcile on a schedule. Silent divergence is the failure mode — a wrong book shows up in fills, not in logs — so the state machine refuses to quote until the book is LIVE.

What if both A and B show the same gap?

Correlated loss: either the venue published a gap or the loss is local and common to both paths. Check your own counters first — RcvbufErrors, NIC drops, consumer depth — then use the recovery channel or a fresh snapshot. Do not trade the instrument until it is repaired.

Do I need to handle out-of-order UDP?

Yes. Sequence numbers exist because reordering happens; buffer briefly and reorder rather than treating a reorder as a gap. The caveat is the buffer window — bound it, so a genuine gap is still detected quickly.

Is capture affordable at line rate?

Cheaper than one dispute you cannot answer. Ring-buffer to fast local storage with hardware stamps, roll to object storage, and keep the compliance window. It is the evidence layer for disputes, audits and latency regressions, not an optimisation.

Further reading

Drills · 6

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Pick the strongest answer

After every restart your book is subtly wrong — a few price levels stay stale until the next full refresh. The code requests the snapshot, applies it, then subscribes to increments. Where is the bug?

  1. The snapshot is stale and the venue should be asked for a fresher one. A snapshot is a point in the sequence; it is fine as long as you replay from that point.
  2. The receive buffer is too small. That would show as gap counters and UdpRcvbufErrors, not as a consistent post-restart pattern.
  3. The join order: everything published between the snapshot and the subscription is lost. Subscribe and buffer increments first, then apply the snapshot, then replay buffered increments from the snapshot's sequence. The gap between snapshot and subscription is exactly the missing data.
  4. Increments must be applied newest-first. Increments are strictly in sequence order.
In short

The join order is wrong: subscribe to increments first, then apply the snapshot, then replay what you buffered.

Why

This is the classic market-data ordering bug and it is invisible in testing on a quiet instrument. The fix is a state machine: BUFFERING → SNAPSHOT_APPLIED → REPLAYING → LIVE, with the book untrusted until it reaches LIVE.

The common mistake

Blaming a stale snapshot or the buffer. A snapshot is just a point in the sequence; the hole is everything published between the snapshot and the subscription.

Read the docs

2 Scenario: what do you do next?

For the last three sessions, your feed handler reports gaps for the first sixty to ninety seconds after the open, then runs clean all day. The venue reports no issues and your NIC shows zero drops.

Step 1. First check?

  1. Raise the receive buffer and see whether it goes away. Likely to help and likely to hide the real cause; measure first so you know whether the consumer is the constraint.
  2. Escalate to the venue with the gap log. They will point at your clean NIC and your socket drops.
  3. Switch to their TCP feed. Trades a fixable local problem for head-of-line blocking on the hot path.
  4. Socket-level counters and consumer behaviour during that window: UdpRcvbufErrors, the socket's own drop count from ss -uanm, and consumer queue depth — a clean NIC with socket drops means the application fell behind. The pattern (only at peak, NIC clean) points at buffer plus consumer, and the counters separate them.

Step 2. Socket drops match the gaps exactly; queue depth peaks at the buffer limit and the receive thread also writes a JSON audit log. Fix?

  1. Move the logging (and any other work) off the receive thread onto a consumer pool, raise rmem_max and set SO_RCVBUF from the measured burst, then verify across a full open with the counters flat. Removes the cause and raises the absorber, verified against the event that exposed it.
  2. Just raise the buffer to 64 MB. It buys time for a consumer that still cannot keep up; the next busier open re-opens the ticket.
  3. Drop the audit log entirely. It may be a compliance artefact; move it, do not delete it.
  4. Add a second feed handler in parallel. Duplicates the same bottleneck and doubles the reconciliation problem.

Step 3. Prevention?

  1. Monitor gaps only — they are the user-visible signal. Gaps are the consequence; queue depth and socket drops are the leading indicators.
  2. Document the workaround in the runbook. Not a mechanism.
  3. Peak-replay load test in CI for the handler, alerts on socket drops and queue depth with thresholds below the point where gaps appear, and a sizing note that is re-derived when venue message rates grow. Catches the regression before an open does, and keeps the sizing honest as rates rise.
In short

First check the socket drop counters and the consumer queue depth; then move the logging off the receive thread and raise the buffer.

Why

Interviewers like this one because everything external looks clean. The signal is knowing that ss -uanm shows per-socket drops, that peak-only symptoms mean absorber-versus-consumer, and that the receive thread should never do I/O.

The common mistake

Raising the buffer and moving on. A bigger bucket buys time for a consumer that still cannot keep up; the next busier open re-opens the ticket.

Read the docs

3 Read the output

The desk says the exchange is dropping packets. Where is the loss really, and what do you change?

$ nstat -az | grep -E 'Udp(InErrors|RcvbufErrors|InDatagrams)'
UdpInDatagrams              884120114          0.0
UdpInErrors                   2214087            0.0
UdpRcvbufErrors               2214081            0.0
$ sysctl net.core.rmem_max net.core.rmem_default
net.core.rmem_max = 212992
net.core.rmem_default = 212992
$ ss -uanm | grep -A1 ':14310'
UNCONN 0  0  233.72.0.1:14310  *:*
  skmem:(r0,rb212992,t0,tb212992,f0,w0,o0,bl0,d2214081)
$ ethtool -S eth2 | grep -iE 'drop|discard' | head -3
rx_dropped: 0
rx_queue_0_drops: 0
  1. In the socket receive buffer: 2.2M RcvbufErrors with rb=212992 and the NIC dropping nothing. Raise net.core.rmem_max to tens of megabytes and set SO_RCVBUF explicitly in the receiver, then confirm the counter stays flat through an open. The drop counter on the socket (d2214081) and RcvbufErrors match; the NIC is clean.
  2. The multicast group is misconfigured; check IGMP. You are receiving 884M datagrams, so membership is working.
  3. The venue is publishing gaps; open a ticket. The loss is provably on your host.
  4. The NIC is dropping frames; increase ring size. rx_dropped and per-queue drops are zero.
In short

The socket receive buffer is too small and is dropping packets; raise net.core.rmem_max and set SO_RCVBUF in the receiver.

Why

ss -uanm shows the socket's receive buffer size and its own drop count, which is the fastest way to prove local loss. Note that raising rmem_max alone is not enough — the application must ask for the larger buffer with SO_RCVBUF.

Read the docs

4 Find what's broken

Four of these lines will cost money at the open. Which four — and which would you change first?

# feed handler deployment
streams = ["A"]
recv_buffer_bytes = 262144
consumer_threads = 1
consumer_does = ["parse", "build_book", "write_json_log", "publish"]
capture = "off"
sizing_basis = "average message rate over the trading day"
gap_policy = "log and continue"
In short

The four bad lines are trading on through gaps, doing all the work on the receive thread, sizing from the daily average, and taking only stream A.

What's broken
  • Line 8: A gapped book is treated as a logging event and trading continues on data known to be wrong.
  • Line 5: The socket-draining thread also parses, builds the book, writes a JSON log and publishes — so it falls behind during bursts and the kernel drops.
  • Line 7: Capacity is sized from the daily average, when the peak is an order of magnitude higher and is exactly when correctness matters.
  • Line 2: Only one of the redundant streams is consumed, so any single-path loss becomes a gap.
Why

A 256 KB buffer (line 3) is too small but is a symptom of the sizing basis; capture off (line 6) is a real risk but not what breaks the open. The four that bite are trading through gaps, doing work on the receive thread, sizing from the average, and consuming only one of the redundant streams.

Read the docs

5 Answer out loud

How would you build market-data ingestion for a desk on three venues — transport, book construction, loss handling, capacity and capture? Five to seven sentences.

In short

A strong answer stops quoting an instrument when its book has a gap, keeps the receive thread only draining, and captures every packet as evidence.

What a strong answer does
  • correctness: A/B de-duplication, buffer-then-snapshot-then-replay state machine, per-instrument sequence, gap → untrusted → recovery, receive thread that only drains.
  • operations: Gaps, last-message age, UdpRcvbufErrors, NIC drops, consumer queue depth, and cross-checking against a reference; peak-based sizing with replay load tests.
  • evidence: Line-rate capture with hardware timestamps, retention for the regulatory window, searchable by instrument and sequence.
  • communication: Transport → book → loss → capacity → capture, with the failure modes named at each step.
Why

Strong answers make wrongness loud (untrusted state, automatic stop), keep the receive path minimal, and treat capture as the evidence layer.

6 Quick recall

Joining a feed: do you take the snapshot first or subscribe to increments first?

In short

Subscribe to increments first, then apply the snapshot, then replay the buffered increments.

Accepted

increments first then snapshot · subscribe to increments first · buffer increments then apply the snapshot

Why

Subscribe to increments and buffer, then apply the snapshot, then replay buffered increments from the snapshot's sequence. Snapshot-first loses everything published in between.

Next lesson Trading-day operations: the open, the close, incident response with money moving, and change freezes
Drill · Market data
0:00

Loading…