Skip to content

Sequence: Place Order (Happy Path)

The Orders service acts as saga orchestrator. It issues commands to Inventory and Payment Gateway and waits for outcomes before confirming.

sequenceDiagram
    autonumber
    actor Customer
    participant GW as API Gateway (Kong)
    participant OS as Orders Service
    participant IS as Inventory Service
    participant PG as Payment Gateway
    participant ES as EventStoreDB
    participant KB as Kafka

    Customer->>GW: POST /v1/orders {items, paymentToken}
    GW->>OS: POST /orders (validated JWT)

    OS->>ES: Append OrderPlaced event
    OS->>KB: Publish OrderPlaced → chakra.orders.placed

    OS->>IS: ReserveStock(orderId, items)
    IS->>IS: Acquire row lock; check stock levels
    IS-->>OS: StockReserved (reservationId)

    OS->>ES: Append OrderAwaitingPayment event

    OS->>PG: CapturePayment(paymentToken, total)
    PG-->>OS: PaymentCaptured (paymentRef)

    OS->>ES: Append OrderConfirmed event (paymentRef)
    OS->>KB: Publish OrderConfirmed → chakra.orders.confirmed

    OS-->>GW: 201 Created {orderId, status: Confirmed}
    GW-->>Customer: 201 Created

Notes

  • The saga is synchronous within the request: the customer receives a 201 only after stock is reserved and payment is captured.
  • If payment fails after stock reservation, the Orders service triggers compensation — see saga compensation diagram.
  • EventStoreDB optimistic concurrency prevents duplicate order IDs (INV-ORD-010).
  • The OrderConfirmed event triggers downstream choreography (Fulfillment Gateway, analytics) independently.