Design: Order Tracking State Machine
Design the state machine logic, API interface, and data model for order states. Out of scope: payment processing, inventory management.
Functional Requirements
Non-Functional Requirements
Jump into concepts and practice - no test required
Order Tracking State Machine in system design?transition('placed', 'shipped', event='ship_order') correctly moves from placed to shipped on ship_order event; others reverse or skip states incorrectly.transition('placed', 'shipped', event='ship_order') [OK]state = 'placed'
event = 'ship_order'
if state == 'placed' and event == 'ship_order':
state = 'shipped'
elif state == 'shipped' and event == 'deliver_order':
state = 'delivered'
print(state)event = 'deliver_order' when state = 'placed'?state = 'shipped'
event = 'cancel_order'
if state == 'placed' and event == 'cancel_order':
state = 'cancelled'
elif state == 'shipped' and event == 'cancel_order':
print('Cannot cancel after shipping')
else:
state = 'cancelled'
print(state)