Skip to content

Courier deliveries

delivery-service (port 4006) is the last-mile courier. It books a delivery for every paid order, hands it to a simulated courier when the warehouse ships, and shows it through the stack's first micro-frontend. It only reads the shop's commerce events; the order itself keeps following the warehouse's shipment.

flowchart LR
    B[backend] -->|order.paid, shipment.shipped,<br>order.cancelled, shipment.delivered| Q[(delivery-service queue<br>or event feed)]
    Q --> D[delivery-service]
    D --> C{{simulated courier}}
    C --> D
    FE[frontend /orders/:id/delivery] -->|imports /mfe/delivery/remote.js| D

What a tester sees

  1. Pay an order: within seconds GET /api/v1/orders/{id}/delivery answers a BOOKED delivery with an AWX… tracking code.
  2. As warehouse, pick, pack and ship the order: the delivery becomes PACKED.
  3. The courier moves it every step interval (15 s locally, 1 min on the server): IN_TRANSIT, OUT_FOR_DELIVERY, then DELIVERED or FAILED_ATTEMPT. After two failed attempts the parcel is RETURNING and then RETURNED.
  4. The order page links to Courier delivery status, which renders the timeline and test controls from delivery-service's web component.

Making it deterministic

Control Request
One step now POST /api/v1/deliveries/{id}/courier/advance
Script the next attempts PUT /api/v1/deliveries/{id}/courier/script {"attempts":["FAIL","DELIVER"]}
Freeze the courier for this delivery PUT /api/v1/deliveries/{id}/courier/paused {"paused":true}

Unscripted attempts are decided by a hash of the order id, the attempt and the seed, so the same order always gets the same outcome.

Exercises

  • Cancel a paid order before shipping and check the delivery is CANCELLED; cancel after shipping and see the backend refuse it.
  • Script ["FAIL","FAIL"], advance to RETURNED, then let the warehouse's own carrier deliver the shipment: the delivery keeps RETURNED and shows discrepancy = true. Which system is right?
  • Track a parcel anonymously with GET /api/v1/deliveries/track/{code} and check what it hides.
  • Stop delivery-service and open the delivery page: the rest of the shop keeps working and the page explains that tracking is unavailable.

Details: delivery-service contract.