Skip to main content

Checkout runbook

Checkout is the retail network's storefront purchase saga: it opens a checkout session from a shopper's cart, authorizes the payment with customer-payments, places the customer order with customer-ordering as the pivot and confirms the delivery promise, with compensating voids and five clock-driven sweep policies cleaning up the sessions that stall on the way (ADR 0001, ADR 0003). It deploys as up to three binaries from one image: the api (always on), the read-only MCP server (optional) and the read-only A2A agent (optional). This runbook covers all of them and what to do when they misbehave. Settings are in Configuration, metrics and logs in Observability, symptom lookups in Troubleshooting.

Runtime shape​

The image (Dockerfile) builds every cmd/* into /app/<name> and runs as uid 1000 with a read-only root filesystem; the default ENTRYPOINT is ./api and the chart picks command: ["/app/mcp"] or ["/app/a2a"] for the optional components. EXPOSE 8080 8090 8093.

ComponentBinaryPortDefault in chartWhat runs in it
apicmd/api:8080always onREST, the transactional outbox relay, the five saga policies
mcpcmd/mcp:8090mcp.enabled=falseread-only MCP server (/mcp, /), GET /healthz
a2acmd/a2a:8093a2a.enabled=falseread-only A2A agent (/, /a2a), Agent Card, GET /healthz

cmd/api wires, in one process:

  • REST API on HTTP_ADDR: POST /checkout-sessions, GET /checkout-sessions/{sessionId}, POST /checkout-sessions/{sessionId}/confirmations, GET /healthz, GET /readyz (internal/adapters/inbound/http/server.go). Both POSTs require an Idempotency-Key.
  • Outbox relay: polls outbox_events and publishes pending rows to Kafka (internal/adapters/outbound/outbox).
  • Five policies, each on its own tick: ResolveInDoubtPlacements (15 s), ResolveStuckAuthorizations (30 s), RetryOwedVoids (1 m), ExpireOnQuoteExpiry (1 m) and PurgeStoredPlacements (1 h).

There is no in-memory mode and no worker that can be switched off. If the relay or a policy returns on its own, the process exits non-zero (<name> stopped unexpectedly: exiting so the orchestrator restarts the service) so the orchestrator replaces the pod (cmd/api/main.go).

cmd/mcp and cmd/a2a run the SAME GetSession read use case over the same Postgres database, run the idempotent embedded migrations at boot like cmd/api, and never start the relay or a policy, never dial Kafka and never call a sibling. There is NO authentication on either (fleet-wide decision, ADR 0005, ADR 0007): access control is the in-cluster ClusterIP boundary plus whatever the gateway allows.

Dependencies​

DependencyUsed forSource
Postgres (via PgBouncer)every write and read of all binaries; DATABASE_URL is the pooled DSNSecret (database.existingSecret), key DATABASE_URL
Postgres (direct DSN)boot migrations only; MIGRATIONS_DATABASE_URLsame Secret, key MIGRATIONS_DATABASE_URL, optional (falls back to DATABASE_URL)
Kafka (KAFKA_BROKERS)outbox relay sink and the /readyz broker check (cmd/api only)chart value kafka.brokers
shopping-cart (REST)the saga reads the cart (config.shoppingCartUrl)in-cluster sibling base URL
delivery-promise (REST)pre-check the selected offers (config.deliveryPromiseUrl)in-cluster sibling base URL
pricing (REST)issue the binding price quote (config.pricingUrl)in-cluster sibling base URL
customer-payments (REST)authorize and void the payment (config.customerPaymentsUrl)in-cluster sibling base URL
customer-ordering (REST)place the order, the saga pivot (config.customerOrderingUrl)in-cluster sibling base URL
OTel CollectorOTLP/gRPC traces and metricsotel.endpoint (default otel-collector.observability.svc.cluster.local:4317)
  • All five sibling URLs are MANDATORY: cmd/api exits at boot naming the first missing one (cmd/api/config.go) and the chart refuses to render without them.
  • The Collector is never on the request path: exporters dial lazily, so a Collector that is down costs telemetry and nothing else (ADR 0006).

Deployment​

Helm chart​

charts/checkout (Chart.yaml name checkout) renders the api Deployment, Service, ConfigMap, Secret (only when database.url is given), ServiceAccount and optional Ingress, Gateway API HTTPRoute and HPA, plus the mcp-* and a2a-* Deployment, Service and route when enabled. The chart refuses to render without database.url or database.existingSecret, kafka.brokers and the five config.*Url values, naming the missing one.

helm install checkout ./charts/checkout \
--set database.existingSecret=checkout-db \
--set kafka.brokers=kafka:9092 \
--set config.shoppingCartUrl=http://shopping-cart:80 \
--set config.deliveryPromiseUrl=http://delivery-promise:80 \
--set config.pricingUrl=http://pricing:80 \
--set config.customerPaymentsUrl=http://customer-payments:80 \
--set config.customerOrderingUrl=http://customer-ordering:80

Optional components:

helm upgrade --install checkout ./charts/checkout ... --set mcp.enabled=true --set a2a.enabled=true

mcp.route.enabled=true exposes the MCP server at the gateway path /api/mcp/checkout (prefix rewritten to /mcp) on Service checkout-mcp:8090; a2a.route.enabled=true exposes the agent at /api/a2a/checkout (prefix rewritten to /) on Service checkout-a2a:8093, with the Agent Card at /api/a2a/checkout/.well-known/agent-card.json. Requests to the A2A agent carry the A2A-Version header. In-cluster without a route: http://checkout-mcp:8090/mcp and http://checkout-a2a:8093/. A2A_AGENT_URL defaults to http://<release>-a2a.<ns>.svc.cluster.local:8093/ and a2a.agentUrl overrides it.

How the fleet's local cluster deploys it (warehouse-infra develop, helm-values/checkout.yaml): database Secret checkout-db (DATABASE_URL and MIGRATIONS_DATABASE_URL keys), the five sibling URLs at http://<service>.warehouse-systems.svc.cluster.local:80, a Gateway API route at /api/checkout with the prefix stripped, and the A2A component enabled with its route at /api/a2a/checkout. The MCP component is left off there. terraform/apps.yaml registers checkout as a service with database: true.

Chart invariants are asserted by charts/checkout/tests/ (render_test.sh, test_service_selectors.py) and run in CI by the helm-lint and chart-tests jobs: the env ConfigMap is mounted, mandatory values refuse to render, DATABASE_URL is only ever a secretKeyRef, extraEnv refuses any *_MODE and any *_CONSUMER_GROUP, every Service selects exactly one Deployment, and the mcp and a2a Deployments never receive Kafka, sibling or sweep variables. The packaging checklist is Before the first release.

Release​

A push to main runs docker-publish (image ghcr.io/iqvo/checkout:<short sha> and latest, cosign-signed, SBOM attested) and release (next vX.Y.Z tag, image re-tagged, chart pushed to oci://ghcr.io/iqvo), after every other CI job is green (see Testing).

Probes and what readiness waits for​

ProbePathSettings
startupGET /healthzevery 2 s, 30 failures (about 60 s, covering the bounded Postgres retry)
livenessGET /healthzinitial delay 5 s, every 10 s
readinessGET /readyzinitial delay 3 s, every 5 s
  • GET /healthz is liveness only, on all three binaries. Never flipped by dependencies or by shutdown.
  • GET /readyz (cmd/api only) is 200 {"status":"ready"} only while (a) the pod is not draining AND (b) a Postgres ping AND a Kafka broker metadata request both answer. The dependency verdict is cached 3 s and one round of checks is bounded 2 s (internal/adapters/inbound/http/readiness.go). While draining the answer is 503 {"status":"not_ready"}; while a dependency is down it is 503 application/problem+json, type /problems/dependency-unavailable, detail not ready: postgres or not ready: kafka. The cause is in the WARN log readiness: dependency is not ready.
  • Kafka down: /readyz 503 but REST writes are still accepted; the events wait in outbox_events. Postgres down: /readyz 503 and REST writes fail. In both cases /healthz stays 200, so probes do not restart the pod.

Graceful shutdown​

Sequential (cmd/api/main.go, cmd/api/workers.go): /readyz flips to 503, wait SHUTDOWN_DRAIN_DELAY (5 s), drain HTTP (10 s bound), stop the five policies one after the other (10 s each), stop the relay (10 s), close the pool. Worst case 75 s; the chart refuses a terminationGracePeriodSeconds that does not exceed drain + 70 s (default 80). The relay stops last so nothing committed by the policies is stranded.

Migrations​

Two embedded migrations (internal/adapters/outbound/postgres/migrations): 0001_checkout_schema creates checkout_sessions, idempotency_keys and outbox_events; 0002_idempotency_key_global makes the Idempotency-Key the sole primary key of idempotency_keys (the route column goes). Migrations run at boot, in all three binaries, over MIGRATIONS_DATABASE_URL (falling back to DATABASE_URL), inside a bounded retry: 5 attempts with 1, 2, 4 and 8 s backoff (15 s total), because the first outbound dial of an injected pod can be reset by the mesh sidecar. After the last attempt the process refuses to boot and logs the last error. schema_migrations records version 2, dirty f. There is no manual migration step.

Kafka​

This context produces two topics and consumes none:

TopicEventsKeyConsumers
retailnetwork.checkout.eventsCheckoutCompletedsessionIdshopping-cart, customer-payments (per apis/asyncapi.yaml)
retailnetwork.checkout.analyticsCheckoutOpened, CheckoutDeclined, CheckoutRequoteRequired, CheckoutFailed, CheckoutSessionExpired, CheckoutPlacementInDoubtsessionIdnone
  • Consumer groups: none. There is no consumer, so there is no group id to choose, reset or lag to monitor.
  • DLQ: none. There is nothing to dead-letter on the consumer side. The producer-side equivalent is an outbox row that reached the attempt cap (see below).
  • The writer uses RequiredAcks=All, a key-hash balancer (one aggregate on one partition, in order) and AllowAutoTopicCreation; the service never creates topics through an admin API. A broker with auto-creation off needs both topics created by hand.
  • Every message is a CloudEvents 1.0 envelope in structured mode with header content-type: application/cloudevents+json; charset=UTF-8 (ADR 0004); the W3C traceparent of the request that raised the event is also stamped into the headers.

Outbox relay​

Every state change writes its events to outbox_events in the same Postgres transaction as the session. The relay (internal/adapters/outbound/outbox) then drains it:

  • A pass claims up to 100 unpublished rows in id order with FOR UPDATE SKIP LOCKED (two replicas never claim the same row), sends them one at a time and marks each published_at after Kafka acknowledged it. A full batch is followed immediately by another pass; otherwise the relay sleeps OUTBOX_RELAY_INTERVAL.
  • On the first send failure the pass stops (a later event of the same session must never overtake an earlier one), records attempts + 1 and last_error on that row and logs outbox relay pass failed.
  • Delivery is at-least-once. The CloudEvents id is minted once when the row is written, so a redelivery carries the same id for the consumer to de-duplicate.
  • A row whose attempts reached OUTBOX_MAX_ATTEMPTS (20) is excluded from claims, logged once at ERROR (outbox relay: row reached the attempt cap and is excluded from future claims; re-arm it with attempts = 0 after fixing the cause, with outbox_id, topic, event_type, key) and later rows overtake it.

Inspect and re-arm:

SELECT count(*) FROM outbox_events WHERE published_at IS NULL;
SELECT id, event_type, subject, attempts, last_error
FROM outbox_events WHERE published_at IS NULL ORDER BY id;
-- after fixing the cause (usually Kafka):
UPDATE outbox_events SET attempts = 0 WHERE id = <id>;

The saga policies (sweepers)​

PolicyTickFindsDoes
ResolveInDoubtPlacements15 s (INDOUBT_SWEEP_INTERVAL)PLACING sessions whose next_attempt_at is duere-sends the stored placement request with the same Idempotency-Key (the sessionId); settles a definitive answer; alerts at 20 h; gives up and voids at 22 h
ResolveStuckAuthorizations30 s (STUCK_SWEEP_INTERVAL)AUTHORIZING for 2 minutes or morere-calls AuthorizePayment with the SAME key <sessionId>:auth:<attempt> and the kept token, which yields the true outcome
RetryOwedVoids1 m (VOID_SWEEP_INTERVAL)sessions with void_authorization_id setvoids the authorization (<sessionId>:void) until it succeeds
ExpireOnQuoteExpiry1 m (EXPIRY_SWEEP_INTERVAL)OPEN or DECLINED sessions past quote_expires_atmoves them to EXPIRED
PurgeStoredPlacements1 h (PURGE_SWEEP_INTERVAL)closed sessions 24 h after terminal_at that still hold a placement bodydrops the stored request (raises no event)

Each tick drains its backlog in batches of 200 (a full batch means there may be more). A failing tick is logged (scheduled sweep failed; trying again at the next tick) and retried at the next one, never fatal. Several replicas are safe: a session another actor already moved is skipped, and every transition is an optimistic-version save.

Alerts are ERROR log lines "msg":"ALERT" with a stable alert field: placement-in-doubt-20h, placement-given-up-22h, place-order-rejected, authorization-mismatch, sibling-contract-violation. See Observability.

Configuration in the chart​

Env varChart valueDefaultNotes
HTTP_ADDRconfig.httpAddr:8080port must equal service.targetPort
LOG_LEVELconfig.logLevelinfodebug, info, warn/warning, error
DATABASE_URLSecret key database.existingSecretKeyrequiredpooled DSN; never in the ConfigMap
MIGRATIONS_DATABASE_URLSecret key database.migrationsExistingSecretKeyDATABASE_URLdirect DSN, boot migrations only
KAFKA_BROKERSkafka.brokersrequiredcomma-separated
SHOPPING_CART_URLconfig.shoppingCartUrlrequired
DELIVERY_PROMISE_URLconfig.deliveryPromiseUrlrequired
PRICING_URLconfig.pricingUrlrequired
CUSTOMER_PAYMENTS_URLconfig.customerPaymentsUrlrequired
CUSTOMER_ORDERING_URLconfig.customerOrderingUrlrequired
SIBLING_TIMEOUTconfig.siblingTimeoutbinary: 5sempty means not rendered
CUSTOMER_ORDERING_TIMEOUTconfig.customerOrderingTimeoutbinary: 15sempty means not rendered
INDOUBT_SWEEP_INTERVALconfig.indoubtSweepIntervalbinary: 15s
STUCK_SWEEP_INTERVALconfig.stuckSweepIntervalbinary: 30s
VOID_SWEEP_INTERVALconfig.voidSweepIntervalbinary: 1m
EXPIRY_SWEEP_INTERVALconfig.expirySweepIntervalbinary: 1m
PURGE_SWEEP_INTERVALconfig.purgeSweepIntervalbinary: 1h
OUTBOX_RELAY_INTERVALconfig.outboxRelayIntervalbinary: 1s
OUTBOX_MAX_ATTEMPTSconfig.outboxMaxAttempts200 = unlimited
SHUTDOWN_DRAIN_DELAYconfig.shutdownDrainDelaybinary: 5swhole seconds or minutes; sizes the grace period
ENVIRONMENTenvironmentproduction
SERVICE_VERSIONimage.tag (else appVersion)
OTEL_SERVICE_NAMEotel.serviceNamecheckoutrendered only with otel.enabled=true; mcp gets <name>-mcp, a2a <name>-a2a
OTEL_EXPORTER_OTLP_ENDPOINTotel.endpointin-cluster Collectorrendered only with otel.enabled=true

The mcp component renders only MCP_ADDR (mcp.httpAddr), LOG_LEVEL, DATABASE_URL / MIGRATIONS_DATABASE_URL, SERVICE_VERSION, ENVIRONMENT, OTEL_SERVICE_NAME and OTEL_EXPORTER_OTLP_ENDPOINT; the a2a component the same with A2A_ADDR (a2a.httpAddr) and A2A_AGENT_URL (a2a.agentUrl) in place of MCP_ADDR. Anything else is never rendered into them; the selector test fails the chart if it is.

Idempotency-Key middleware​

internal/adapters/inbound/http/idempotency.go:

  • Both POST routes require an Idempotency-Key header of 1 to 128 printable ASCII characters (400 idempotency-key-required when absent, 400 idempotency-key-invalid when malformed or longer than 128).
  • A 2xx and a refusal whose problem type is FINAL or OUTCOME are stored per key for 24 h (internal/application/idempotency); the key is global to the service, and the stored fingerprint covers the method, the path and the SHA-256 of the body. The class of every problem type is declared on its catalogue entry (errors.go, ADR 0011).
  • A repeat with the same request replays the stored response with header Idempotency-Replayed: true (only on a replay); the same key with a different request whose answer was stored is 409 idempotency-key-reused. A 5xx, a RETRYABLE refusal (concurrent-update, cart-not-checkout-ready, placement-in-doubt, void-pending, illegal-transition, not-found, validation-failed, offer-not-quotable, price-quote-rejected) and a refusal with no class are never stored: nothing is written, the key is released, a retry under it runs the command again and another body under it is a new request. Requests with one key are serialised in the process: after a stored first answer concurrent identical requests run the command once; after a released first one the next copy runs the command itself. Across replicas both may run and the first stored record wins.
  • An expired record is ignored on read and overwritten by the next write for the same key, but no policy deletes idempotency_keys rows (see Troubleshooting).

Failure modes​

Pod crash-loop​

  • Symptom: restarts climb, the WarehousePodRestarting alert fires.
  • Diagnosis: kubectl -n warehouse-systems logs deploy/checkout --previous shows service exited with error naming the missing variable (cmd/api/config.go), migration or ping exhaustion (internal/bootretry), or <worker> stopped unexpectedly. The mcp pod logs mcp server exited with error, the a2a pod a2a agent exited with error.
  • Action: fix the named chart value or Secret key, then roll again.

Postgres unreachable​

  • Symptom: /readyz 503 naming postgres; REST writes fail; the MCP server and A2A agent cannot serve sessions (every read is a Postgres query).
  • Action: restore Postgres/PgBouncer. The relay and the policies resume on their own and nothing needs replaying; the pod is not killed. The readiness verdict refreshes within 3 s of recovery.

Kafka unreachable​

  • Symptom: /readyz 503 naming kafka; REST writes still accepted and queued.
  • Diagnosis: SELECT count(*) FROM outbox_events WHERE published_at IS NULL; grows while brokers are down.
  • Action: restore the brokers; the relay drains in id order automatically. Rows that reached the attempt cap need the re-arm statement above.

A sibling is down​

  • Symptom: 503 <sibling>-unavailable from the POST routes (shopping-cart-unavailable, delivery-promise-unavailable, pricing-unavailable, customer-payments-unavailable, customer-ordering-unavailable). Open fails cleanly with no state change. A confirm whose authorization or place-order outcome is unknown answers 202 and the session sits in AUTHORIZING or PLACING for the policies.
  • Diagnosis: the request log line names the route and status; the WARN logs authorization outcome unknown, the session stays AUTHORIZING and the policy log lines name the session.
  • Action: restore the sibling. The stuck and in-doubt policies resolve the half-finished sessions on their own; nothing to replay by hand.

PLACING sessions that do not resolve​

  • Symptom: an ALERT placement-in-doubt-20h, then placement-given-up-22h.
  • Diagnosis: SELECT session_id, placement_attempts, next_attempt_at, updated_at FROM checkout_sessions WHERE state = 'PLACING'; (the backoff doubles from 30 s to 15 min). Check customer-ordering reachability and whether it holds a result for Idempotency-Key = <sessionId>.
  • Action: fix customer-ordering. At 22 h the session becomes FAILED (placement-unresolved) with the void owed, inside customer-payments' 24 h backstop and the network's 24 h idempotency window.

Authorization mismatch​

  • Symptom: 409 authorization-mismatch on a confirm and an ALERT authorization-mismatch: customer-payments authorized an amount or currency that is not the quote total. The session returns to DECLINED with the void owed.
  • Action: investigate customer-payments; the void is attempted at once and retried every minute by RetryOwedVoids.

Owed voids that do not clear​

  • Diagnosis: SELECT session_id, state, void_authorization_id FROM checkout_sessions WHERE void_authorization_id IS NOT NULL;
  • Action: restore customer-payments. A 404, or a 409 illegal-transition (already voided, captured or expired), counts as done.

idempotency-key-reused storms​

  • Symptom: a burst of 409 idempotency-key-reused.
  • Diagnosis: callers reuse a key while regenerating the body after a stored answer (a 2xx, or a FINAL or OUTCOME refusal). Correct replays come back with Idempotency-Replayed: true and are not a fault. After a RETRYABLE refusal the key is free: another body under it is a new request.
  • Action: fix the caller to keep the body byte-stable per logical request, or mint a fresh key.

Routine procedures​

  • Restart: kubectl -n warehouse-systems rollout restart deploy/checkout (and deploy/checkout-mcp / deploy/checkout-a2a when enabled).
  • Logs: Loki, app=checkout (JSON on stdout; raise config.logLevel to debug for a noisy pod).
  • In-cluster REST: Service port 80 to container 8080; the external path is the gateway route /api/checkout (prefix stripped).
  • Scale: the HPA is off by default (autoscaling.api). More than one replica is safe for the relay (row claims) and the saga writes (optimistic version saves) but has not been load-tested.
  • Roll back: helm rollback checkout. Migration 0002 drops the route column of idempotency_keys, so an image from before the REST guideline cutover cannot write idempotency keys on a migrated database: roll back the whole cutover set together.
  • Look at one session: GET /checkout-sessions/{sessionId} (REST), the MCP tool get_checkout_session or the A2A skill checkout_session_status; all three read the same row.