Replay an Order Event Log Through a Lifecycle State Machine
Last updated: November 29, 2026
Quick Overview
Given a log of order events (create, accept, reject, fill, cancel), replay them through an explicit state machine and return each order's final state and filled quantity, plus the indices of events that were invalid for the order's state.
Coinbase
November 29, 20260
0
0 solved
Given a log of order events (create, accept, reject, fill, cancel), replay them through an explicit state machine and return each order's final state and filled quantity, plus the indices of events that were invalid for the order's state.
Coinbase trading systems reconcile order state from event streams, and support engineers need to know exactly which events were illegal. The interviewer checks that transitions are explicit, terminal states are respected and overfills are caught.
What the Interviewer Expects
- Name the states and allowed transitions before coding
- Treat FILLED, CANCELLED and REJECTED as terminal
- Reject fills that exceed the remaining quantity
- Record invalid events without crashing the replay
- Keep partial fills when an order is cancelled
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you make this replay idempotent if events can be duplicated?
- How would you handle events arriving out of order with sequence numbers?
- How would you express the transitions as a table instead of if branches?
- What metrics would you emit from this replay in production?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Events are (order_id, kind, arg). States: PENDING after create, OPEN after accept, PARTIAL after a fill that leaves quantity, then FILLED, CANCELLED or REJECTED as terminal. Return `{id: (state, fil...
High-Level Design
Keep a dict of order records. Create validates the id is new and quantity positive. Every other event looks up the order; unknown or terminal orders make the event invalid. Then check the (state, even...