Warehouse fulfilment¶
warehouse-service turns paid orders into parcels (from 1.5.0 possibly
several per order, see Split shipments). The backend does not
store shipments; it mirrors the progress in orders.fulfilment_state, which
drives the cancellation rules the customer sees.
Endpoints under /api/v1/warehouse require ROLE_WAREHOUSE or ROLE_ADMIN
(demo user warehouse / warehouse; UI page /warehouse).
Endpoints¶
| Method and path | Result |
|---|---|
GET /api/v1/warehouse/queue |
PAID orders without a shipment, oldest first |
POST /api/v1/warehouse/shipments {orderId} |
Create a shipment (AWAITING_PICK); the order must be PAID and unreleased (409 otherwise or when one exists) |
GET /api/v1/warehouse/shipments?status= |
List |
GET /api/v1/warehouse/shipments/{id} |
One shipment as stored; read-only since warehouse-service 1.3.1 (cancellations arrive through the event feed) |
GET /api/v1/warehouse/shipments/{id}/pick-list |
Items to pick |
POST /api/v1/warehouse/shipments/{id}/pick |
AWAITING_PICK → PICKED |
POST /api/v1/warehouse/shipments/{id}/pack {weightKg} |
PICKED → PACKED; weight 0.01–30.00 kg |
POST /api/v1/warehouse/shipments/{id}/ship {carrier, trackingNumber?} |
PACKED → SHIPPED; omit trackingNumber for the simulated carrier |
POST /api/v1/warehouse/shipments/{id}/deliver |
SHIPPED → DELIVERED (manual confirmation) |
POST /api/v1/warehouse/shipments/{id}/carrier/advance |
Fast-forward a simulated parcel one scan |
POST /api/v1/warehouse/shipments/{id}/cancel |
Only in AWAITING_PICK or PICKED: cancels the order; warehouse-service restores the stock asynchronously from the stock.restore-requested feed event (from 1.6.0, usually within a few seconds) |
GET /api/v1/orders/{id}/shipment |
Owner or admin: the order's shipment |
Any other transition is 409.
Carriers and tracking numbers¶
| Carrier | Manual tracking number format | Nominal transit (estimate) |
|---|---|---|
INPOST |
24 digits | 1 day |
DPD |
14 digits | 2 days |
DHL |
10 digits | 2 days |
UPS |
1Z + 16 upper-case letters or digits |
3 days |
A supplied number that does not match its carrier is 400; a blank string is
also 400.
The workflow¶
sequenceDiagram
actor O as Operator
participant W as warehouse-service
participant B as Backend
O->>W: Create shipment
W->>B: Read order (PAID?)
W->>B: AWAITING_PICK
O->>W: Pick
W->>B: PICKED
O->>W: Pack (weight)
W->>B: PACKED
O->>W: Ship (carrier)
W->>B: SHIPPED
W->>B: Email request
O->>W: Deliver
W->>B: DELIVERED
Customer cancellation reaches the warehouse¶
The backend never calls warehouse-service. When a customer or admin cancels an
order that is already released (AWAITING_PICK), the backend records
order.cancelled in its event feed in the
cancelling transaction, and warehouse-service picks it up on its next poll.
sequenceDiagram
actor C as Customer
participant B as Backend
participant F as Event feed
participant W as warehouse-service
actor O as Operator
C->>B: Cancel order 42
Note over B: fulfilmentState CANCELLED
B->>F: order.cancelled (same transaction)
B-->>C: 200 CANCELLED
Note over F: Feed position assigned on commit
W->>F: Poll order.cancelled (every 5 s)
F-->>W: order.cancelled, order 42
Note over W: Shipment CANCELLED, lastActor system
O->>W: Pick shipment
W-->>O: 409
| Shipment state when the event arrives | Result |
|---|---|
AWAITING_PICK, PICKED |
CANCELLED, lastActor = "system"; no call back to the backend |
PACKED, SHIPPED |
Left alone and logged (the backend refuses those cancellations) |
| Finished, already cancelled, or no shipment | Ignored |
The shipment is cancelled up to about 5 seconds after the order. An operator
who acts inside that window gets 409 Order was cancelled by the customer and
the shipment is cancelled on the spot.
Two state machines, kept in step¶
stateDiagram-v2
direction LR
state "Shipment (warehouse-service)" as S {
[*] --> AWAITING_PICK: create
AWAITING_PICK --> PICKED: pick
PICKED --> PACKED: pack
PACKED --> SHIPPED: ship
SHIPPED --> DELIVERED: deliver / carrier
AWAITING_PICK --> CANCELLED: cancel
PICKED --> CANCELLED: cancel
}
Backend fulfilmentState:
NONE → AWAITING_PICK → PICKED → PACKED → SHIPPED → DELIVERED, plus
CANCELLED from NONE/AWAITING_PICK (customer or admin) or
AWAITING_PICK/PICKED (warehouse cancel).
| Backend rule | Result |
|---|---|
PUT fulfilment AWAITING_PICK |
Only for PAID orders in NONE; repeating it is a no-op 200 |
| Other steps | Next forward step only; skips, backward steps and steps after CANCELLED → 409 |
SHIPPED / DELIVERED |
Also set the order status |
Customer or admin cancel while NONE or AWAITING_PICK |
Allowed; stock, coupon and tenders restored |
Customer or admin cancel from PICKED on |
409 Order is already being packed and cannot be cancelled |
Legacy admin status change while AWAITING_PICK … SHIPPED |
409 |
Consistency with the backend¶
- Validate locally → call the backend → persist. A failed backend call
leaves no local change. Backend
4xxkeep their status and message;5xx, timeouts and a rejected service token become503 {"message":"Backend unavailable"}. - Lost release response. On
503during create, the service reads the order again and keeps the shipment if the release reached the backend; an order alreadyAWAITING_PICKwithout a shipment can be released again (it is adopted). - Event feed (every 5 s).
order.cancelledevents cancel the shipment as shown above. The poller keeps its cursor inevent_cursorsand the ids it handled inprocessed_events, so a repeated event changes nothing. - Reconciler (every 10 minutes, safety net). Cancels
AWAITING_PICKshipments whose order is cancelled but whose event was missed, and adopts orders the backend reports asAWAITING_PICKwithout a shipment if they are older than two minutes. Reading a shipment or a refused transition reconciles immediately and answers409 Order was cancelled by the customer. - Notifications use a transactional outbox with retries; the backend sends
one email per
requestId.
Contract: Warehouse service contract.
Split shipments¶
warehouse-service runs several warehouse locations: KRK "Krakow
Central" (priority 1) and GDN "Gdansk North" (priority 2). A product is
stocked by category (PRIMARY or BACKUP per location); the demo seed makes a
mixed cart split.
flowchart LR
O[Paid order 42<br/>phone + book] --> A{Allocate lines}
A -->|one active location<br/>stocks every line| P1[1 parcel]
A -->|otherwise: highest-priority<br/>active location per line| P2[Parcel 1/2 KRK<br/>Parcel 2/2 GDN]
A -->|no active location<br/>for a category| X[409, nothing created]
POST /api/v1/warehouse/shipments {orderId}still answers201with the first parcel, now withparcelCount.- Customers read every parcel with
GET /api/v1/orders/{id}/shipments(locationCode,locationName,parcelIndex,parcelCount,lines[]);GET /api/v1/orders/{id}/shipmentkeeps its shape for the first parcel. - Admin:
GET /api/v1/warehouse/locations,PUT /api/v1/warehouse/locations/{code}{active},POST /api/v1/warehouse/shipments/{id}/reallocate{targetLocation?}(onlyAWAITING_PICKparcels),POST /api/v1/warehouse/shipments/{id}/short-pick{productId, missingQuantity}andGET /api/v1/warehouse/reconciliation.
The backend still sees one fulfilmentState. warehouse-service mirrors
max(last mirrored, aggregate), where the aggregate is AWAITING_PICK while
every parcel awaits pick and otherwise max(PICKED, min over non-cancelled
parcels): the first pick makes the order PICKED (the customer can no longer
cancel), and the order is SHIPPED only when every parcel shipped. The rule
and why the backend keeps one state are in
ADR 2.
Test ideas: deactivate GDN and release a mixed order (one parcel, or 409
for a category only GDN stocks); short-pick a line and watch a second parcel
appear; compare GET /api/v1/warehouse/reconciliation before and after.