Track Shipment Milestones From Out-of-Order Carrier Events
Last updated: November 29, 2026
Quick Overview
Carrier status messages for a shipment (gate in, loaded, departed, arrived and so on) arrive late, duplicated and out of order. Implement a timeline object that ingests events idempotently, reports the current milestone, and flags timestamps that contradict the milestone order.
Flexport
November 29, 20260
0
0 solved
Carrier status messages for a shipment (gate in, loaded, departed, arrived and so on) arrive late, duplicated and out of order. Implement a timeline object that ingests events idempotently, reports the current milestone, and flags timestamps that contradict the milestone order.
Flexport's shipment page merges EDI and API feeds from ocean carriers, terminals and truckers, and they rarely agree on order or timing. This practical coding round checks idempotency, ordering by business meaning rather than arrival order, and how you surface bad data to operations instead of hiding it.
What the Interviewer Expects
- Deduplicate by a stable event id so retries are harmless
- Derive status from the furthest milestone reached, not the last message received
- Treat a repeated milestone report as a correction and say how corrections are chosen
- Flag anomalies such as departed before loaded rather than dropping events
- Discuss persistence and concurrency once it leaves memory
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- Two sources report different departure times. How do you choose, and how do you show it?
- How would you make apply safe under concurrent consumers on the same shipment?
- How would you replay a month of events after fixing a parsing bug?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Events are (event_id, milestone, event_time) for one shipment. Milestones have a fixed business order: BOOKED, GATE_IN, LOADED, DEPARTED, ARRIVED, DISCHARGED, GATE_OUT, DELIVERED. Duplicate ids are ...
High-Level Design
Keep a set of seen ids, and a map from milestone to its latest reported time. Status is computed from the map by rank, so arrival order of messages never matters: a DEPARTED that arrives before GATE_I...