What happened
A shipping network processed carrier events asynchronously. A shipment moved through CREATED, PICKED_UP, IN_TRANSIT, and DELIVERED states. The carrier’s webhook delivery was at-least-once, and messages were placed on a queue before being processed by the shipment service.
During a regional network disruption, the DELIVERED event arrived and was processed before a delayed IN_TRANSIT event. The consumer applied both events in arrival order, without comparing event sequence numbers or validating the current state transition. The late IN_TRANSIT event changed the shipment from DELIVERED back to IN_TRANSIT.
Customer notifications then told recipients that a delivered package was still moving. The warehouse dashboard reopened completed work, and customer support had to manually reconcile affected shipments. Duplicate-event handling existed, but out-of-order delivery had never been tested.
Root cause
The consumer assumed delivery order was equivalent to business event order. Tests covered normal event sequences and duplicate delivery but not stale events arriving after newer state transitions.
The fix
The team added aggregate versions and transition rules. Events older than the last applied version are ignored or routed to reconciliation, and illegal state regressions are recorded for investigation. Tests now replay event streams with duplicates, delays, and deliberate reordering.
Testing gaps and preventive tests
Out-of-order event replay, state-machine transition validation, sequence and version checks, and reconciliation behavior for events that arrive late. Event-driven systems must defend their state against delayed and reordered messages, not merely duplicate messages.
Business impact
Conflicting shipment status, duplicate support work, and incorrect operational reporting.
Lesson learned
Event-driven systems must defend their state against delayed and reordered messages, not merely duplicate messages.