ADR 0008: Adopt the fleet REST API guideline
Status
Accepted (2026-11-01). Replaces the per-route Idempotency-Key store, the 422 answer for key reuse and every
:verb route of the cart contract.
Context
The 2026-10-30 application portfolio assessment measured the fleet's REST contracts: write operations only
partly keyed, two spellings of the replay header, key reuse answered 422 in most services and 409 in one,
three command-URL styles (:verb, verb sub-paths, sub-resources) and lists without paging. shopping-cart
showed four of those:
- seven command routes in the
:verbor verb-segment style (:set-quantity,:remove,:set-destination,:quote-delivery,:select-delivery,:merge-into,/delivery/requoted), and a consumed route in the same style (POST /delivery-offers:quoteon delivery-promise); - the replay header was spelled
Idempotent-Replayedand a reused key was answered 422; - keys were scoped per route and stored by a get-then-put that ran after, and outside the unit of work of, the cart change: two concurrent first requests could both run, and a crash between the change and the put left a cart change without its key row;
GET /cartsanswered a bare{carts: [...]}with no paging.
The fleet standard (warehouse-docs, "REST API guideline", rules R1-R8) removes each of those. This ADR adopts it here, as a hard cutover: no alias route, no dual header, no toggle.
Decision
-
Noun routes (R1, R2). Status codes and response bodies do not change with a rename;
operationIds stay, so the A2A and MCP mappings do not move.Old New POST /carts/{cartId}/lines/{catalogItemId}:set-quantityPUT /carts/{cartId}/lines/{catalogItemId}POST /carts/{cartId}/lines/{catalogItemId}:removeDELETE /carts/{cartId}/lines/{catalogItemId}POST /carts/{cartId}:set-destinationPUT /carts/{cartId}/destinationPOST /carts/{cartId}:quote-deliveryPOST /carts/{cartId}/delivery-quotesPOST /carts/{cartId}:select-deliveryPUT /carts/{cartId}/delivery-selectionPOST /carts/{cartId}:merge-intoPOST /carts/{cartId}/mergesPOST /carts/{cartId}/delivery/requotedPOST /carts/{cartId}/delivery-requote-acceptancesTestRetiredRoutesAreGoneasserts every old route answers 404 or 405. -
Idempotency (R3-R6, R8). Every
POST(create, add line, delivery-quotes, merges, delivery-requote-acceptances) sits behindRequireIdempotencyKey(store, clock), applied per route.PUTandDELETEare idempotent by method; a key sent to them is accepted and ignored. The key is 1 to 128 printable ASCII characters: absent is 400idempotency-key-required, malformed is 400idempotency-key-invalid. The fingerprint is method + path + SHA-256 of the body: the same key and fingerprint replays the stored answer (status, body,Content-Type) withIdempotency-Replayed: true, and only a replay carries the header; the same key with another fingerprint is 409idempotency-key-reused, never 422. -
A global, durable key store joined to the unit of work (R4, STANDARD 2.5). The key is global, no longer per route (the
routecolumn ofidempotency_keysholds the empty string; no migration). The port isports.IdempotencyStore.Do(ctx, key, requestHash, at, fn): Postgres claims the key row inside the transaction it opens, handsfnthat transaction through the context (every unit of work joins it instead of opening its own), and commits the claim, the cart change, the outbox rows and the stored answer together. Concurrent requests with one key are serialised by the unique index and the loser replays the winner's answer. A 2xx or 4xx answer is stored for 24 hours; a 5xx or a panic rolls everything back and is never stored, so the retry re-executes. The in-memory store implements the same contract and is run by the same repository contract suite. -
Keyset paging (R7).
GET /cartstakeslimit(1 to 500, default 100) andcursor, orders by(created_at, cart_id)descending in both the Postgres and the in-memory repository, uses the fleetpagepackage (internal/adapters/inbound/http/page) and answers{items, nextCursor}; a bad value is 400invalid-limitorinvalid-cursor. The A2Alist_shopper_cartsskill keeps its own tool schema but follows every page, 100 carts at a time, up to 1000 carts (the newest), so it still returns complete data. -
Contract and enforcement.
apis/openapi.yamldeclares theIdempotency-Keyparameter (required: the middleware is active in every runtime mode), 400 and 409 and theIdempotency-Replayedheader on every 2xx of everyPOST, and theCartPageschema. Therest-guidelineSpectral rule (.spectral.yaml,.spectral/functions/restGuideline.js) runs in theapi-lintjob with--fail-severity=warn. -
Consumers changed in this repo. The delivery-promise gateway (
internal/adapters/outbound/deliverypromise) now callsPOST /delivery-quotesand always sends theIdempotency-Keyof the cart request (ADR 0002 A10), and its contract-test copy of the provider spec is the renamed one. There is no web remote and no seed script here. Callers of this service (storefront-bff, via its allow-list) update in their own pull requests.
Exemptions
None. GET /carts is the only collection and it is paged. GET /carts/{cartId}, /healthz and /readyz
are not collections.
Consequences
- Breaking for every caller: new URLs, the list envelope, a key required on every
POST. This pull request must deploy together with the rest of the REST cutover set (storefront-bff, delivery-promise and the other services);developis half-migrated until the last of them lands. - A client that reused one
Idempotency-Keyacross two different routes used to get two answers; it now gets 409idempotency-key-reused. A UUID per logical submit avoids it. - The key row, the cart change and the outbox rows can no longer diverge: a crash rolls all three back.
- Rows the per-route store wrote (under their route name) are not read by the global lookup and expire in 24 hours.
- Keyset paging cannot skip or repeat a cart that shares a creation instant with its neighbour; the walk is covered by the repository contract suite (memory and Postgres) and by the HTTP tests.
Update (2026-11-20)
ADR 0011 narrows the sentence "A 2xx or 4xx answer is stored for 24 hours" of Decision 3: 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.