FIX Sequence Gaps – Why They Happen and How to Repair Them
Understanding Sequence Numbers
Tag 34 (MsgSeqNum) in FIX protocol ensures message ordering and detects lost messages. Each message in a session must have a sequence number that increments by 1. A gap occurs when the expected sequence number doesn't match the received number.
Gap Scenarios
Scenario 1: Missing Message
Expected sequence 5, but received sequence 6. Message 5 was lost in transit.
Message 4: 8=FIX.4.4|9=123|35=D|11=ORD004|34=4|... Message 5: (MISSING) Message 6: 8=FIX.4.4|9=123|35=D|11=ORD006|34=6|... Gap detected: Expected 5, received 6
Scenario 2: Out-of-Order Delivery
Messages arrive out of order due to network routing. Sequence 6 arrives before sequence 5.
Received: 34=6 (arrived first) Expected: 34=5 Action: Buffer message 6, wait for 5
Scenario 3: Duplicate Sequence
Same sequence number received twice, indicating a retransmission or duplicate send.
Message 1: 8=FIX.4.4|...|34=5|... Message 2: 8=FIX.4.4|...|34=5|... (DUPLICATE) Error: Duplicate sequence number detected
Sample FIX Logs
Normal Sequence Flow:
34=1|35=A|... (Logon) 34=2|35=D|... (NewOrderSingle) 34=3|35=8|... (ExecutionReport) 34=4|35=D|... (NewOrderSingle) 34=5|35=8|... (ExecutionReport) ✓ Sequence continuous
Sequence Gap Detected:
34=1|35=A|... 34=2|35=D|... 34=3|35=8|... 34=5|35=D|... (GAP: Missing 4) Error: Sequence gap detected. Expected 4, received 5
Recovery Methods
- ResendRequest (35=2): Request retransmission of missing messages
35=2|7=4|16=4| (Request resend of sequence 4)
- SequenceReset (35=4): Reset sequence numbers to a new value
35=4|36=10|123=Y| (Gap fill: reset to sequence 10)
- Logout and Reconnect: Start a fresh session with sequence 1
- Manual Sequence Reset: Use ResetSeqNumFlag (141=Y) to reset
Best Practices
- Monitor sequence numbers continuously and alert on gaps immediately
- Implement automatic resend request logic for small gaps (1-10 messages)
- Use sequence reset for large gaps or after extended downtime
- Log all sequence events for audit and troubleshooting
- Validate sequence numbers before processing business logic
- Handle out-of-order messages with buffering when possible
Detect sequence gaps automatically: Upload your FIX logs to FIX Doctor for instant sequence gap detection and analysis.
Upload FIX Log