Design: Order State Machine
Design focuses on the order state machine logic, APIs for state transitions and queries, concurrency control, and audit logging. Does not cover payment processing, shipping logistics, or UI design.
Functional Requirements
FR1: Support order lifecycle states: Created, Paid, Shipped, Delivered, Cancelled, Returned
FR2: Allow valid state transitions only (e.g., Created -> Paid, Paid -> Shipped)
FR3: Reject invalid transitions (e.g., Delivered -> Paid)
FR4: Provide ability to query current state of an order
FR5: Support concurrent updates safely to prevent invalid state changes
FR6: Log state changes for audit and debugging
FR7: Handle up to 1000 state transitions per second
Non-Functional Requirements
NFR1: Latency for state transition API should be under 100ms p99
NFR2: Availability target 99.9% uptime
NFR3: System must be scalable to handle 10,000 concurrent orders
NFR4: State transitions must be consistent and atomic