ADR 0011: Postgres and Kafka are the only runtime
Status
Accepted (2026-10-19). Fleet decision of 2026-10-19: "everything must use real
database and broker". Supersedes the in-memory, log and permissive
statements of ADR 0001,
ADR 0003 and
ADR 0005 (each carries a one-line pointer
here). Sixth service of the fleet migration, after product-master, workforce-management,
facility-layout, labor-performance and process-path-management.
Context
Until now the shipped binaries had silent fallbacks, each a way to boot "healthy" and lose data:
cmd/apiandcmd/mcpwithoutDATABASE_URLran on in-memory adapters (internal/adapters/outbound/memory): state lost on restart,cmd/mcpandcmd/apieach with their own empty store.EVENT_PUBLISHERdefaulted tolog: the outbox relay marked rows published after writing them to the log. Nothing reached Kafka.KAFKA_BROKERSwas optional.PRODUCT_MODEandDOCK_DOOR_MODEdefaulted topermissive: neither consumer started and every SKU and door code was accepted./readyzreported only the shutdown drain gate, so a pod with a dead Postgres or Kafka stayed in the Service.
The chart rendered those defaults (eventPublisher: "log", both modes
permissive, kafka.enabled: false). warehouse-infra already overrides all of
them (eventPublisher: kafka, both modes kafka with stable groups,
kafka.enabled: true, the platform brokers), so the cluster has been running
the real wiring; the repository defaults were the lie.
Decision
-
Mandatory configuration, boot error otherwise, raised by
loadConfigbefore anything is opened or the listener binds, naming the variable:cmd/api:DATABASE_URL,KAFKA_BROKERS,PRODUCT_CONSUMER_GROUP,DOCK_DOOR_CONSUMER_GROUP.cmd/mcp:DATABASE_URL(it reads the same Postgres; it needs no Kafka).cmd/inbound-projector:ANALYTICS_DATABASE_URL,KAFKA_BROKERS(unchanged). ItsANALYTICS_CONSUMER_GROUPkeeps its fixed defaultinbound-receiving-analytics: it is a name, not a mode switch.cmd/inbound-reports:ANALYTICS_DATABASE_URL(unchanged; no Kafka).
-
The
*_MODEnames stay (docs and warehouse-infra set them) but the only mode iskafka, and it is the default.PRODUCT_MODEandDOCK_DOOR_MODEset topermissiveoroffare boot errors (PRODUCT_MODE=permissive is not supported: this context runs on real Kafka); an unknown value stays a boot error. Both consumers always start, and the SKU and door copies are always enforced onPOST /asnsandPOST /appointments.GET /docksand the MCPlist_docksalways reportmode: kafka. The use cases keep theirModeparameter:permissiveis still a valid value for unit and BDD tests, and nothing undercmd/**can select it. -
EVENT_PUBLISHERis kept because the chart and warehouse-infra set it. Unset orkafkais accepted;logis a boot error (EVENT_PUBLISHER=log is not supported: this context publishes to real Kafka). The relay is always on;OUTBOX_MAX_ATTEMPTSkeeps its default of 20 (ADR 0007). The log sink is no longer wired by any binary. -
No in-memory runtime path in
cmd/**. The memory adapters stay ininternal/adapters/outbound/memoryas test doubles (unit, handler and BDD tests).TestRuntimeBinaryHasNoInMemoryAdaptersfails the build if a non-test file undercmd/**imports them, andTestRuntimeBinarySensorBitesproves the detector flags a plain, aliased, blank and dot import and passes look-alikes and comments. The clock and id generator the binary needs already live inadapters/outbound/clockandidgen, so nothing moved. -
Readiness is real.
GET /readyzis 200 only while the drain gate is open AND Postgres answers a ping AND a Kafka broker answers a topic-less metadata request. A failure is a 503application/problem+json(dependency-unavailable, detailnot ready: postgres, kafkanaming the failing dependencies); draining stays{"status":"not_ready"}. The verdict is cached 3 s and a round is bounded to 2 s, so probes cannot hammer either dependency; the check ignores the caller's cancellation. The Kafka check dials a fresh connection per call (kafka-go'sClient.Metadatawould keep answering from a cached cluster layout after the broker is gone) and never requires topics: the relay writer setsAllowAutoTopicCreationand the broker auto-creates the output topics on first write, so a not-ready pod, which receives no traffic, could never be driven to create them./healthzstays liveness only. The projector's/readyz(admin port) follows the same rule with the analytical database in place of the OLTP one.cmd/inbound-reportsandcmd/mcpserve only/healthzand are unchanged. -
NUL guard. A
rejectNULmiddleware answers404 resource-not-foundfor a NUL (U+0000) in the request path and400 malformed-requestfor one in a body (a raw byte or the\u0000escape), before routing and before the Idempotency-Key middleware, so a rejected request never records its key. PostgreSQL text cannot hold NUL (SQLSTATE 22021, then 25P02) and on sibling services a fuzzed NUL became a 500 on the real runtime. Here the domain value objects already reject control characters in every field, and a probe of every path, query and body field on the real runtime found no 500, so this is defence in depth: one uniform answer, and a field added later without validation cannot reintroduce the defect. -
Migrations at boot stay (with
internal/bootretrybackoff;MIGRATIONS_DATABASE_URLfallback unchanged). The service never creates topics (the relay and consumers log the topics they use). A topic that does not exist yet is created by the broker on the first write; the first relay publish may fail once withUnknown Topic Or Partitionwhile that happens and succeeds on the next pass (the relay retries, the row is not lost). -
The proof.
cmd/apiTestRunOnRealPostgresAndKafka(integration tag) boots the realrun(ctx)in-process against testcontainers Postgres and Kafka and drives it only through REST and Kafka: it feeds both local copies from Kafka (a duplicate delivery is deduped by CloudEvents id), asserts the SKU copy is enforced (422 before the ProductRegistered event, 201 after), walks ASN, appointment and receipt, asserts the rows in Postgres, the CloudEvents envelope and key on both output topics, an idempotent replay, the NUL guard, a restart with no loss and no duplicate, and/readyzfollowing Postgres and then Kafka going away.cmd/mcpkeeps its Postgres integration test. -
Chart.
database.url|existingSecret,kafka.brokersand both consumer groups are required (the render fails naming the value);productMode,dockDoorModeandeventPublisherdefault tokafkaand refuse anything else;extraEnvmay not setEVENT_PUBLISHERother thankafkanor any*_MODE;KAFKA_BROKERSand the groups are always rendered.kafka.enabledis kept only because warehouse-infra sets it:trueor absent, neverfalse. The chart tests render warehouse-infra's current values (tests/warehouse-infra-platform-values.yaml+tests/warehouse-infra-values.yaml) and prove they still render with every required variable present: no infra values change is needed. -
Local run.
docker-compose.ymlbrings up Postgres 16 and Kafka (confluent-local, KRaft); the README and the quickstart run the real binaries against them. -
A dead worker is a dead service. Observed on a real run: when the broker goes away, kafka-go's reader returns a dial error, both consumer goroutines log
... stoppedand return, and the process stayed up and/readyzwent green again once Kafka was back, with no consumer running.cmd/apinow watches the relay and both consumers and exits non-zero (<worker> stopped unexpectedly: exiting so the orchestrator restarts the service) when one returns on its own, exactly ascmd/inbound-projectoralready did. The integration test stops Kafka and asserts the exit.
Consequences
- A misconfigured deployment fails at boot with the variable named, instead of coming up "healthy" with no relay, no consumers and no state.
- Local development needs Docker (
docker compose up -d --wait); the 1-command in-memorygo runis gone. Unit and BDD tests are unaffected (they use the test doubles). - A fresh deployment enforces the SKU and door copies from the first request:
until the consumers have replayed
warehouse.product-master.eventsandwarehouse.facility.events, a write returns422 unknown-sku/unknown-dock-door(/readyzdoes not wait for the consumers, see the runbook). That is the behaviour the cluster already had. GET /docksandlist_dockscan no longer reportpermissive.- A Kafka outage that outlasts a consumer's dial error restarts the pods (decision 11) instead of leaving them alive with dead consumers; with the broker down they are not ready anyway.
- A consumer that starts while its topic does not exist yet (a fresh cluster
before the first product-master or facility-layout event) does not pick the
topic up once it appears: verified on a real broker, it stayed silent for
more than two minutes and consumed at once after a restart.
/readyzdoes not wait for it (topics are never required). Production topics exist; on a fresh environment publish the first events (or create the topics) before starting the service, or restart it afterwards (quickstart, runbook). Failing readiness or the worker on a missing consumed topic is a follow-up. - A Kafka outage makes every pod not ready (the verdict is cached 3 s), so
the Service stops routing to it. Rows already committed wait unpublished in
outbox_eventsand the relay drains them on recovery. - The
contractjob: this repository has no Schemathesis job in.github/workflows/ci.ymlor the Makefile, so there is nothing to move onto service containers. Adding one is a separate decision.
Out of scope
*_MODE=permissive|httpfor REST edges to sibling contexts: none exists in this service (it consumes siblings only through Kafka and calls none over REST), so there is nothing to follow up here.- A Schemathesis
contractjob (see above) and the Postgres-backed Idempotency-Key hook it would need; the idempotency store is already the Postgres one in the shipped binary. analyticsstore.Memory, an in-memory store used by the analytics contract test, lives in the production package; no binary imports it. Moving it under a test-only package is a follow-up.- warehouse-infra: no change is required.