ADR 0016: 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". Amends (does not rewrite) the in-memory, log and
opt-in statements of ADR 0004
(the demand consumer's off switch), ADR 0007
(LogSink as the default publisher) and ADR 0008
(cmd/mcp on in-memory repositories without DATABASE_URL). No CloudEvents
type, payload, topic or REST contract changes.
Context
Until this ADR every binary had a degraded default that looked healthy:
cmd/apiandcmd/mcpwithoutDATABASE_URLbooted on the in-memory repositories (memory.NewProcessCapacityRepo,memory.NewOutboxRepo, ...): no persistence, no idempotency table, an outbox nobody could read back.EVENT_PUBLISHERdefaulted tolog: the relay drained the outbox into a log line and marked every row published, so a deployment without the setting silently lost every event (ADR 0007).KAFKA_BROKERSwas optional: without it the labor and storage consumers were "disabled (logged, not fatal)" and the order-demand consumer stayed off unlessDEMAND_CONSUMER_GROUPwas set (ADR 0004).- The labor and storage consumer groups defaulted to the names the in-cluster pod uses, so a process run locally joined the live group.
cmd/planning-projectordefaultedANALYTICS_CONSUMER_GROUP, and its/readyzonly reported the shutdown flag;cmd/planning-reportshad no/readyz./readyzofcmd/apionly reported the shutdown flag, so a pod whose Postgres or Kafka was gone stayed "ready".cmd/apistayed alive with a dead consumer or relay (the failure mode found by inbound-receiving #48).
Decision
- No in-memory runtime path in
cmd/**.cmd/api,cmd/mcp,cmd/planning-projectorandcmd/planning-reportsrun on real Postgres and real Kafka only. The adapters ininternal/adapters/outbound/memory(andanalyticsstore.NewMemory) stay as TEST DOUBLES for unit and BDD tests.TestRuntimeBinaryHasNoInMemoryAdaptersfails when a non-test file undercmd/**imports the memory package;TestRuntimeBinarySensorBitesproves the detector. - Mandatory configuration is a boot error that names the variable, before
the listener binds (
loadRuntimeincmd/api/runtime.go):DATABASE_URL,KAFKA_BROKERS,LABOR_CAPACITY_CONSUMER_GROUP,STORAGE_CAPACITY_CONSUMER_GROUP,DEMAND_CONSUMER_GROUP,DEMAND_SITE_ID.cmd/mcprequiresDATABASE_URL;cmd/planning-projectorrequiresANALYTICS_DATABASE_URL,KAFKA_BROKERSandANALYTICS_CONSUMER_GROUP. No consumer group has a default any more. EVENT_PUBLISHERstays only because the chart and warehouse-infra set it: unset orkafkais accepted,logand any other value are boot errors (EVENT_PUBLISHER=log is not supported: ...).- Consumers and relay are always on. The order-demand consumer loses its
off switch (this amends ADR 0004). There is no
*_MODEvariable in this repo, so nothing needed thepermissive/offrejection other siblings added. /readyzis real.cmd/api: drain gate AND a Postgres ping AND a Kafka broker answering a metadata request. The request names no topics (an empty, non-nil list), so the answer never depends on a topic existing: the relay writer setsAllowAutoTopicCreationand the service never requires or creates topics. The verdict is cached 3 s and bounded 2 s. A failed dependency is503 application/problem+json, typedependency-unavailable,detail: "not ready: postgres"/"not ready: kafka"./healthzstays liveness.cmd/planning-projector: drain gate, analytical Postgres ping and Kafka metadata.cmd/planning-reportsgains/readyz: drain gate and the analytical Postgres ping.cmd/apiexits non-zero, naming the worker, when the relay or a consumer returns on its own (<worker> stopped unexpectedly: exiting so the orchestrator restarts the service), mirroring inbound-receiving #48. The graceful-shutdown order is unchanged.rejectNUL. A NUL (U+0000) in the path, the query or a JSON body reaches a Postgres text parameter as SQLSTATE 22021 and then 25P02: a 500 on the real runtime that the in-memory adapters hid (found by facility-layout #209). The router now answers404 resource-not-found(path),400 malformed-request-body(body, raw byte or\u0000escape) and400 malformed-request-querybefore any handler runs. This service has no Idempotency-Key middleware, so no key can be consumed by a rejected request.- Chart.
database.url/database.existingSecret,kafka.brokers, the three consumer groups,demand.siteId(and, with analytics on,analytics.projector.consumerGroup) are required: the render fails naming the value (requireRealRuntime).kafka.enabledis accepted only astrue(warehouse-infra still sets it) andconfig.eventPublisheronly askafka.KAFKA_BROKERSand every consumer variable are always rendered. The reports readiness probe moves to/readyz.charts/warehouse-planning/tests/ warehouse-infra-*-values.yamlare verbatim copies of warehouse-infra'sorigin/developvalues andrender_test.shrenders them and asserts that every mandatory variable is provided. - Local runs.
docker-compose.ymlbrings up Postgres and a single-node Kafka (it must advertisePLAINTEXT_HOST://localhost:<port>, or the first produce fails on the inter-broker address).
Consequences
- A misconfigured pod now refuses to start (and the chart refuses to render)
instead of coming up healthy and losing events. warehouse-infra's current
values already provide every mandatory variable (checked by
render_test.sh); no infra change is needed. GET /demandno longer has an "off" state: with the consumer always on, the expected-demand model fills as soon as order-management publishes.- A Postgres or Kafka outage turns the pod not-ready (traffic stops) without restarting it; a consumer or relay that dies makes the process exit.
- Kafka behaviour seen by the end-to-end test (
cmd/api/e2e_integration_test.go, which boots the realrun()against testcontainers): the first relay write to an output topic that does not exist yet fails once withUnknown Topic Or Partitionand succeeds on the next pass (the broker creates the topic). The test creates the three input topics before booting, as the cluster has them; it therefore does not exercise inbound-receiving's finding that a kafka-go group consumer started BEFORE its topic exists does not pick the topic up until a restart (ADR 0011 there). That behaviour is a kafka-go property, not solved here. - The
memorypackage remains ininternal/adapters/outbound/memoryand the BDD suite and use-case tests keep using it.
Not in scope
- There is no
contract(Schemathesis) job in.github/workflows/ci.ymlor the Makefile, so no CI job was invented or moved; the NUL guard is covered by unit tests and the end-to-end test instead. - This service has no REST/MCP sync edge to a sibling context (
*_MODE=http), so there is nothing to leave untouched on that side. cmd/mcphas no/readyz(its probes stay/healthz) and dials no Kafka: it only writes outbox rows thatcmd/apirelays. A Postgres-aware MCP readiness probe is a follow-up.
Addendum 2026-11-13: current state
Decision 8 counts three consumer groups, which was the set on 2026-10-19. cmd/api now requires five (consumerGroupEnvs in cmd/api/runtime.go:66): ADR 0017 added OBSERVED_CAPACITY_CONSUMER_GROUP and ADR 0020 DOCK_APPOINTMENT_CONSUMER_GROUP. The chart keys are dockAppointments.consumerGroup and observed.consumerGroup (charts/warehouse-planning/tests/render_test.sh:122-123).