Model Order Fulfilment
This tutorial models a proper DDD-style commerce flow with commands, aggregates, events, policies, read models, and integrations.
Scenario
An online retailer wants generated software for checkout and fulfilment. The business cares about stock reservation, payment authorization, shipment release, customer communication, and exception handling.
Bounded Contexts
- Checkout: cart checkout and order placement.
- Payments: authorization, capture, failure, refund.
- Inventory: reservation and release.
- Fulfilment: packing, dispatch, delivery exceptions.
Core Event Timeline
- Cart Checked Out
- Order Placed
- Payment Authorized
- Inventory Reserved
- Order Released For Packing
- Shipment Dispatched
- Delivery Completed
Commands And Aggregates
- Place Order handled by Order, emits Order Placed.
- Authorize Payment handled by Payment Authorization, emits Payment Authorized or Payment Declined.
- Reserve Inventory handled by Inventory Reservation, emits Inventory Reserved or Inventory Reservation Failed.
- Release Order For Packing handled by Order, emits Order Released For Packing.
- Dispatch Shipment handled by Shipment, emits Shipment Dispatched.
Policies
- When Order Placed, authorize payment.
- When Payment Authorized, reserve inventory.
- When Inventory Reserved, release order for packing.
- When Inventory Reservation Failed, notify customer care and propose substitution or backorder.
- When Shipment Dispatched, publish shipment integration event to customer notifications.
Saga Candidate
Promote the flow to an Order Fulfilment Process saga if the business needs a long-running coordinator that tracks payment, inventory, packing, shipment, retries, and compensation. Add compensation commands such as Void Payment Authorization and Release Inventory Reservation.
Read Models
- Customer Order Status: visible to customers.
- Fulfilment Work Queue: visible to warehouse operators.
- Inventory Reservation Exceptions: visible to operations.
- Order Timeline: visible to customer support.
Review Questions
- Can payment be captured before shipment, or only after dispatch?
- Can a partial inventory reservation release a partial shipment?
- Who can override a failed reservation?
- Which events must be published to external systems?