ADR 0006: Adopt the fleet REST API guideline
Status
Accepted (2026-11-01). Replaces the per-route Idempotency-Key store (a get-then-put outside the unit of work),
the 422 answer for key reuse, the Idempotent-Replayed header, the :void command route and the bare
{authorizations} / {refunds} list bodies of the REST contract in ADR 0002.
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. customer-payments
showed these:
- one command route in the
:verbstyle,POST /payment-authorizations/{authorizationId}:void, and an outbound client (to the payment-provider-simulator) that called the provider's verb routes/void,/reauthorizeand/reduce; - the replay header was spelled
Idempotent-Replayedand a reused key was answered 422; - keys were scoped per route (
idempotency_keyswas keyed by(route, key)) and stored by a get-then-put that ran after, and outside the unit of work of, the aggregate change: two concurrent first requests could both run (the commands were individually idempotent through deterministic provider keys, but both ran), and a crash between the change and the put left a change without its key row; GET /payment-authorizationsanswered{authorizations: [...]}andGET /refundsanswered{refunds: [...]}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; the
operationIdstays, so the MCP and A2A mappings do not move.Old New POST /payment-authorizations/{authorizationId}:voidPOST /payment-authorizations/{authorizationId}/voidsPOST /refunds/{refundId}:retryPOST /refunds/{refundId}/retriesTestRetiredRoutesAreGoneasserts the old route answers 404 or 405. -
Idempotency (R3-R6, R8). Every
POST(/payment-authorizations,.../voids,/refunds,/refunds/{refundId}/retries) sits behindRequireIdempotencyKey(store, clock), applied per route; there is noPUT,PATCHorDELETEroute. The key is 1 to 128 printable ASCII characters: absent is 400idempotency-key-required, malformed is 400idempotency-key-invalid(a key longer than 128 characters used to be reported as-required). The fingerprint is method + path + SHA-256 of the body (the query string is no longer part of it): 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. No route was unkeyed before. -
A global, durable key store joined to the unit of work (STANDARD 2.5). The key is global, no longer per route (the
routecolumn ofidempotency_keysholds the empty string; no migration; rows the per-route store wrote under a route name are never read again, and, as before, nothing purges expired rows: an expired row is only replaced when its key comes back). 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, as a savepoint, so the use cases'ErrConcurrentUpdateretry loops still start clean), and commits the claim, the aggregate 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 as Postgres. -
Keyset paging (R7).
GET /payment-authorizations(filtersorderId|checkoutSessionId) andGET /refunds(filterorderId) takelimit(1 to 500, default 100) and an opaquecursor, order by(created_at, id)ascending in both the Postgres and the in-memory repository (AuthorizationRepository.PageBySession,RefundRepository.ListByOrder), use the fleetpagepackage (internal/adapters/inbound/http/page) and answer{items, nextCursor}. A bad value is 400invalid-limitorinvalid-cursor, and a query parameter the list does not declare (the retiredafter,offset,nextToken,from) is 400unknown-query-parameter. A listing byorderIdyields at most the one authorization bound to the order. The MCP toolslist_payment_authorizationsandlist_refundsand the A2A skillsget_payment_statusandget_refund_statuskeep their own tool schemas but follow every page (ListAuthorizations.All,ListRefunds.All, 100 rows at a time, up to 1000 rows, documented in the tool descriptions), so they still return 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(the200ofPOST /payment-authorizations, which the spec did not list, is now documented), and thePaymentAuthorizationPageandRefundPageschemas. Therest-guidelineSpectral rule (.spectral.yaml,.spectral/functions/restGuideline.js) runs in theapi-lintjob with--fail-severity=warn. This repo has no Schemathesis contract job, so noschemathesis.tomlis needed. -
Consumers changed in this repo. The payment-provider client (
internal/adapters/outbound/paymentprovider) now calls the simulator's noun routesPOST /authorizations/{id}/voids,/reauthorizationsand/reductions(it already sent anIdempotency-Keyon every call, and/capturesand/refundswere nouns); itsproviderfaketest double and a wire-path test follow. There is no web remote and no seed script here. Callers of this service (checkout:internal/adapters/outbound/customerpayments) update in their own pull requests.
Exemptions
None. GET /payment-authorizations and GET /refunds are the only collections and both are paged.
GET /payment-authorizations/{authorizationId}, GET /refunds/{refundId}, /healthz, /readyz and /metrics
are not collections.
Amendment: :retry becomes /retries
POST /refunds/{refundId}:retry (use case RetryRefund) was the last :verb route in the fleet. It was
served by the router but missing from apis/openapi.yaml, so the Spectral rule never saw it. It is now
POST /refunds/{refundId}/retries (rule 1.3 d: a lifecycle transition is a transition resource, here the
plural noun retries), described in the spec as operation retryRefund with the Idempotency-Key parameter,
200 (with Idempotency-Replayed), 400, 404, 409 (illegal-transition, concurrent-update or
idempotency-key-reused) and 500. Behaviour, status codes and body are unchanged; hard cutover, no alias.
TestRetiredRoutesAreGone now also asserts that POST /refunds/{refundId}:retry answers 404 or 405. The
only caller known is storefront ops (no consumer in this repository or in the other fleet repos).
Consequences
- Breaking for every caller: a new void URL, the list envelope,
409instead of422for key reuse. This pull request must deploy together with the rest of the REST cutover set (checkout, the payment-provider-simulator 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 aggregate change and the outbox rows can no longer diverge, and two concurrent requests with one key call the provider once: a crash rolls all three back.
- The provider call now happens inside the transaction that holds the key row, like it already did inside the unit of work; a slow provider holds a connection for the length of its timeout.
- Keyset paging cannot skip or repeat a row that shares a creation instant with its neighbour; the walk is covered by the repository contract suite (memory and Postgres), the HTTP tests and a Postgres integration test.
Update (2026-11-19)
ADR 0008 narrows the sentence "A 2xx or 4xx answer is stored for 24 hours" of Decision 2: 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.