Stage 1: Problem
Problem
You are building an e-commerce platform. When a customer places an order, the system must:
- Validate inventory — check each item is in stock, reserve the quantities
- Process payment — charge the customer's payment method, handle 3D Secure if needed
- Create order record — persist the order to the database with line items, totals, and status
- Send notifications — email confirmation to the customer, Slack alert to the fulfillment team
- Update analytics — record the sale amount, category breakdown, conversion funnel step
- Trigger fulfillment — send the order to the warehouse management system (WMS)
- Apply loyalty points — credit the customer's loyalty account based on the purchase
Each subsystem has its own service class with its own methods, error handling, and dependencies. The checkout controller needs to call all 7 services in the right order, handle partial failures (what if payment succeeds but notification fails?), and rollback if critical steps fail (refund if fulfillment can't be triggered).
Other parts of the codebase also need to place orders:
- The mobile API controller
- The subscription renewal service (recurring orders)
- The customer support tool (manual order placement)
- A bulk import script
If the orchestration logic lives in the controller, every caller must duplicate the 7-step sequence. If the order changes (add a fraud check step), every caller must update.
How would you structure this so the complex multi-step order process has a single, simple entry point?