ORIGINAL COMPANY-CONTEXT PRACTICE
Reconcile a simulated order lifecycle
Original practice scenario: A fictional market simulator receives order acknowledgements, fills and cancellations out of order, sometimes more than once. How should its state machine behave?
Written for independent practice using company context; this is not a verified question from a company interview.
A REASONED APPROACH
Model answer.
Represent orders as a constrained event-driven state machine, with execution quantities separate from request status. Arrival order must not erase a valid fill or apply an event twice.
Work through it
- Assign stable order and event identities, record source sequence information and reject events that cannot belong to the referenced order.
- Apply deduplicated events under explicit transitions, maintaining cumulative filled quantity and pending cancellation rather than assuming cancellation removes earlier executions.
- Replay shuffled and duplicated streams, including partial fills during cancellation and sequence gaps; compare reconstructed state with a trusted synthetic ledger.
Tradeoffs to discuss
- Waiting for missing sequence events improves certainty but delays visibility; provisional state requires clearly recorded unresolved gaps.
Common pitfalls
- A cancel request is not a cancellation acknowledgement.
- Do not decrement inventory twice when the same execution is redelivered.