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.
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#
| Pattern | Meaning | Response |
|---|---|---|
| 100, 101, 102 | Normal | Process |
| 100, 101, 104 | Gap: 102 and 103 missing | Recover the missing messages or rebuild state |
| 100, 101, 101 | Duplicate | Ignore the repeat |
| 100, 102, 101 | Out of order | Buffer briefly and reorder, or treat as a gap |
| 5,000 then 1 | Reset | Often a new session or a venue restart; resynchronise |
Where sequence numbers appear#
| Context | Example | Lesson |
|---|---|---|
| Exchange market data feeds | Per channel sequence numbers on multicast feeds | Feed Handlers and Normalization |
| Crypto WebSocket books | Update IDs linking each delta to the previous one | Order Book Feeds: Snapshots and Incremental Updates |
| FIX sessions | MsgSeqNum on every message, with resend requests | FIX Protocol |
| Your own systems | Event IDs in logs and message queues | Logging, Audit Trails and Incident Response |
Recovering from gaps#
| Method | How it works |
|---|---|
| Retransmission request | Ask the venue to resend specific messages; common in FIX and some exchange feeds |
| Snapshot and resync | Request a full current state, then continue with live messages |
| A/B feed arbitration | Many exchanges send the same data on two redundant lines; take each message from whichever arrives first |
| Replay from recordings | Fill 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.
3 quick questions on this lesson. Get them all right to finish it.
Turn on JavaScript to take the quiz.
Mentioned in
- Market Data Levels: Level 1, 2 and 3Programming and Data
- Networking for TradersTrading Infrastructure
- Message QueuesTrading Infrastructure
- Fault Tolerance, High Availability and RedundancyTrading Infrastructure
- Binary ProtocolsTrading Infrastructure