ADR 0010: Adopt the fleet REST API guideline
Status
Accepted (2026-11-01). Builds on ADR 0002
(A13 the order id derives from the Idempotency-Key, A24 the address id does, A26
the order history keyset) and ADR 0003
(the consumed delivery-promise routes). Part of the fleet REST cutover: it deploys
together with every other service of the set (see the warehouse-docs REST guideline).
Context
The 2026-10-30 portfolio assessment found three command-URL styles, two spellings of
the replay header, key reuse answered 422 in most services, lists under per-resource
keys and offset or after paging. customer-ordering had: POST /orders/{orderId}:cancel
(a custom-method suffix), Idempotent-Replayed, key reuse as 422, a key stored per
(route, key) AFTER the handler ran (so the key row was not in the transaction of the
order and its outbox rows, and two concurrent first requests could both run), and
GET /orders paged with after (default 20, maximum 100, 422 on a bad cursor).
Decision
The fleet guideline applies unchanged; nothing in it is a toggle.
- Nouns, not verbs (R1, R2).
POST /orders/{orderId}:cancelbecomesPOST /orders/{orderId}/cancellations(a transition resource, guideline 1.4). The operation idcancelOrder, the status codes and the response body do not change. The old route is gone, with no alias;TestRetiredRoutesAreGonepins it. - Every POST is idempotent (R3-R6, R8). The four POST routes (
/checkout,/orders/{orderId}/cancellations,/shoppers,/shoppers/{shopperId}/addresses) sit behindRequireIdempotencyKey.PUTandDELETEdo not exist in this service. The key is 1 to 128 printable ASCII characters (400 idempotency-key-requiredwhen absent,400 idempotency-key-invalidwhen malformed). The fingerprint is method + path- SHA-256 of the body. A repeat replays the stored answer (status, body,
Content-Type,Location) withIdempotency-Replayed: true; the same key with another fingerprint is409 idempotency-key-reused.Idempotent-Replayedand the422reuse answer are retired everywhere.
- SHA-256 of the body. A repeat replays the stored answer (status, body,
- The key is global and durable.
ports.IdempotencyStoreis now one method,Do(ctx, key, requestHash, at, fn): the Postgres store claims the key inside the transaction it opens, hands that transaction tofnthrough the context (everyUnitOfWork.Doof the use case joins it as a savepoint), and stores the answer in the same commit. The aggregate, the outbox rows and the key row commit or roll back together; a 5xx or a panic rolls back and is never stored; a 4xx is stored and replayed; concurrent requests with one key are serialised by the unique index and the loser replays the winner's answer. No migration:idempotency_keys.routestays and is always the empty string. The in-memory store (unit tests, BDD) holds the store lock for the duration offnand restores its snapshot on failure. - Keyset paging (R7).
GET /orderstakeslimit(1-500, default 100) andcursorand answers{items, nextCursor}. The cursor is the fleetpagepackage (internal/adapters/inbound/http/page, copied unchanged): base64url JSON of the last row'splacedAt(RFC 3339, nanoseconds) andorderId; the repositories, both Postgres and in-memory, order by(placed_at DESC, order_id ASC)and resume strictly after that position.400 invalid-limit,400 invalid-cursorand400 unknown-query-parameter(the retiredafter,offset,nextTokenfail loudly). A missingshopperIdstays422 validation-failed.
Renamed routes
| Old | New |
|---|---|
POST /orders/{orderId}:cancel | POST /orders/{orderId}/cancellations |
GET /orders?shopperId=&after=&limit= (query) | GET /orders?shopperId=&cursor=&limit= |
Exemptions (x-pagination-exempt)
GET /orders/{orderId}/trackingisview: one composite tracking view of one order, bounded by the order's shipment groups; the arrays are parts of that single resource.GET /shoppers?email=isview: the e-mail is unique, so the call is a lookup of one shopper (404 when absent) whose representation contains its saved addresses (at most 20); it is not a collection.
Consumers changed in this repository
internal/adapters/outbound/deliverypromise/gateway.go(the one outbound HTTP client) callsPOST /delivery-quotes,POST /promises/{id}/confirmationsandPOST /promises/{id}/cancellations, and sends anIdempotency-Keyon every POST (the quote mints a fresh UUID per call; promise calls keep<orderId>:<groupNo>[:verb]). The client never reads a collection, so no cursor loop is needed.- The console remote under
web/only issuesGET /orders/{id},/trackingand/ship-to: no change. MCP tools and A2A skills call the use cases, not HTTP. - Other repositories that call these routes (storefront-bff, storefront-web) change in their own pull requests with the strings above.
Consequences
- Breaking by design: new cancel URL,
cursorinstead ofafter, key reuse is409, the replay header is spelledIdempotency-Replayed, the page size bounds moved to 100/500. All pull requests of the cutover merge and deploy as one set. - A checkout now holds its database transaction while it calls delivery-promise (the
key claim has to be in the transaction that stores the order). The call timeout
(
DELIVERY_PROMISE_TIMEOUT, 5 s) bounds it; size the Postgres connection pool for one connection per in-flight checkout. .spectral.yamlenforces R1-R8 in theapi-lintjob; the fleet integration tests (real router, real Postgres) pin fresh key, byte-identical replay,409reuse,400, N concurrent same-key requests with one order, cached4xxand uncached5xx.
Update (2026-11-18)
ADR 0019 narrows the sentence "a 4xx is stored
and replayed" above (and the "cached 4xx" of the Consequences): a 4xx is stored only when its
problem type is FINAL or OUTCOME; a RETRYABLE refusal rolls back, key row included, and is not
stored. The text above is the decision as it was taken.