TradeLabs AILearn

Sequence Numbers, Dropped Packets and Out-of-Order Messages

Sequence numbers let trading systems detect lost, duplicated or out of order messages. Learn how gap detection, recovery and duplicate handling work in practice.

Advanced3 min readUpdated 3 Oct 2026
Markdown
Lesson 25 of 27

When a venue sends a stream of messages, each one usually carries a sequence number that increases by one with every message. That simple counter is one of the most important reliability tools in trading technology. If message 1,001 is followed by 1,004, two messages are missing. If 1,003 arrives twice, one is a duplicate. If 1,005 arrives before 1,004, they are out of order. Without sequence numbers, a system cannot know whether its view of the market or its own orders is complete.

What sequence numbers detect#

PatternMeaningResponse
100, 101, 102NormalProcess
100, 101, 104Gap: 102 and 103 missingRecover the missing messages or rebuild state
100, 101, 101DuplicateIgnore the repeat
100, 102, 101Out of orderBuffer briefly and reorder, or treat as a gap
5,000 then 1ResetOften a new session or a venue restart; resynchronise

Where sequence numbers appear#

ContextExampleLesson
Exchange market data feedsPer channel sequence numbers on multicast feedsFeed Handlers and Normalization
Crypto WebSocket booksUpdate IDs linking each delta to the previous oneOrder Book Feeds: Snapshots and Incremental Updates
FIX sessionsMsgSeqNum on every message, with resend requestsFIX Protocol
Your own systemsEvent IDs in logs and message queuesLogging, Audit Trails and Incident Response

Recovering from gaps#

MethodHow it works
Retransmission requestAsk the venue to resend specific messages; common in FIX and some exchange feeds
Snapshot and resyncRequest a full current state, then continue with live messages
A/B feed arbitrationMany exchanges send the same data on two redundant lines; take each message from whichever arrives first
Replay from recordingsFill gaps from a recorded copy for research data

Sequence numbers for your own orders#

Your systems should also number their events. Combined with unique client order IDs, this lets you detect whether every order acknowledgement and fill was received, which matters when reconnecting after a dropped session. See Alerts, Error Handling and Reconnection and Trade Accounting and Reconciliation.

Implementation tips#

  • Track expected next number per channel, not globally, since venues number channels separately.
  • Set a short reorder window for out of order delivery, then treat missing messages as a gap.
  • Stop using affected state (such as an order book) until recovery completes.
  • Log every gap with its size and time, and alert if gaps become frequent. See Monitoring Positions, P&L and Risk.
  • Handle resets at session start or after venue restarts.

Why gaps happen#

Network packet loss, slow consumers that fall behind and drop messages, venue failovers and your own process restarts. Frequent gaps usually point to a capacity problem on your side, such as a receive buffer that is too small or processing that is too slow. See Networking for Traders.

Frequently asked questions#

What is a sequence number in trading data?#

A counter on each message that increases by one, letting the receiver detect missing, duplicated or out of order messages.

What should I do if my feed has a gap?#

Stop trusting the affected state, recover the missing messages or request a fresh snapshot, then resume.

What is A/B feed arbitration?#

Receiving the same exchange feed on two redundant lines and taking each sequence numbered message from whichever line delivers it first.

Next, learn how to measure delays in your system in Exchange vs Receive Timestamps and Latency Measurement.

Check your understanding

3 quick questions on this lesson. Get them all right to finish it.

Turn on JavaScript to take the quiz.

Finished this lesson?Sign in to save your progress across devices.
Next lessonExchange vs Receive Timestamps and Latency MeasurementHow to measure latency in a trading system: where to timestamp, tick to trade and order round trip, percentiles instead of averages and how to find bottlenecks.

Mentioned in