ADR 0011: Postgres and Kafka are the only runtime
Status
Accepted (2026-10-19). Supersedes the in-memory, permissive and log-sink
statements of ADR 0003,
ADR 0005 and
ADR 0010
(each carries a one-line pointer here; their bodies are history). Additive on
the wire: no event, REST path or migration changes. GET /readyz gains a 503
dependency-unavailable problem.
Context
The user's rule for the whole fleet is "everything must use real database and broker". Until this ADR the shipped binaries of this context could boot into a state that looked healthy and was not:
cmd/apiwithoutDATABASE_URLloggedusing in-memory adaptersand served frominternal/adapters/outbound/memory: no migrations, noIdempotency-Keymiddleware, nothing survived a restart.cmd/mcpdid the same for its read repositories.EVENT_PUBLISHERdefaulted tolog: the relay marked outbox rows published after writing them to the log, so a misconfigured deployment lost every event silently.KAFKA_BROKERSwas optional.DEMAND_MODE,PRODUCT_MODE,LAYOUT_MODEandRELOCATION_MODEdefaulted topermissive(consumer not started); a missing group was an error only inkafkamode, andkafkaover the in-memory adapters only logged a warning./readyzreported only the shutdown gate, so a pod stayed Ready with Postgres or Kafka gone, and it stayed alive with a dead relay or consumer.- The chart mirrored all of it (
eventPublisher: log,*Mode: permissive,kafka.enabled: falseas the default).
cmd/slotting-projector and cmd/slotting-reports already refused to boot
without ANALYTICS_DATABASE_URL (and, for the projector, KAFKA_BROKERS) and
never imported the memory package: they needed no runtime change.
Decision
Postgres and Kafka are the only runtime of every shipped binary. The memory
adapters stay in internal/adapters/outbound/memory as test doubles for unit
and BDD tests.
- Mandatory configuration, a boot error that names the variable, checked
before anything is opened or the listener binds (
loadRuntimeincmd/api):DATABASE_URL,KAFKA_BROKERSand the four consumer groupsDEMAND_CONSUMER_GROUP,PRODUCT_CONSUMER_GROUP,LAYOUT_CONSUMER_GROUP,RELOCATION_CONSUMER_GROUP.cmd/mcprequiresDATABASE_URL. - The
*_MODEnames stay, the only value iskafka(the default). The names are kept because docs and warehouse-infra set them.permissiveandoffexit with<NAME>=permissive is not supported: this context runs on real Kafka; any other value exits with<NAME>: unknown mode "x" (want kafka). All four consumers always start. EVENT_PUBLISHERstays, the only value iskafka(the default), because warehouse-infra sets it.logexits withEVENT_PUBLISHER=log is not supported: this context publishes to real Kafka. The relay is always on;OUTBOX_MAX_ATTEMPTS(default 20) is unchanged./readyzis real: the drain gate AND a Postgres ping AND a Kafka broker answering a metadata request with an empty, non-nil topic list (topics are never required: the relay writer setsAllowAutoTopicCreation: true). The verdict is cached for 3 s and bounded at 2 s. A failure is a 503 problemdependency-unavailablewhose detail namespostgresand/orkafka./healthzstays liveness only.- The process exits non-zero when the relay or a consumer returns on its
own (
<worker> stopped unexpectedly: exiting so the orchestrator restarts the service), instead of staying alive with a dead worker. - NUL guard. Postgres text cannot hold U+0000; a NUL in the path is a 404
resource-not-found, in the body or query a 400malformed-request, refused before any idempotency key is recorded (the in-memory boot hid this defect; it was found by facility-layout's real-Postgres contract run). - Sensor
TestRuntimeBinaryHasNoInMemoryAdapters(and its bites test): no non-test file undercmd/**importsinternal/adapters/outbound/memory. - Chart.
database.*,kafka.brokersand the fourconfig.*ConsumerGroupare required (the render fails naming the value).kafka.enabledis accepted only astrue(warehouse-infra still sets it) and never asfalse; a publisher other thankafka, a mode other thankafka,EVENT_PUBLISHERor any*_MODEinextraEnv, andterminationGracePeriodSecondsunder 20 are refused.charts/slotting-optimization/tests/warehouse-infra-*.yamlare verbatim copies of the warehouse-infra values andrender_test.shasserts every mandatory env is provided by them (it is: no infra change is needed). - Proof.
TestRunOnRealPostgresAndKafkaboots the realrun()against testcontainers Postgres and Kafka and drives it only through REST and Kafka.docker-compose.ymlstarts the same two dependencies for local runs.
Consequences
- A misconfigured deployment now fails at boot (or at chart render) naming the variable, instead of running degraded. A Kafka outage turns the pod unready and, if a worker dies, restarts it; the outbox and the committed offsets make that safe.
- Local runs need Docker (
docker compose up -d --wait). Unit and BDD tests are unchanged: they build the memory doubles directly. - Observed, not fixed: the first relay write to an output topic that does not
exist yet fails once with
[3] Unknown Topic Or Partitionand succeeds on the next pass (the broker auto-creates the topic; the outbox row ends withattempts = 2). inbound-receiving (its ADR 0011) also reports that a kafka-go group consumer that starts before its topic exists may not pick the topic up when it appears until the next restart; that was not measured for this service. cmd/slotting-projectorandcmd/slotting-reportsare unchanged (already real-only).
Out of scope
*_MODE=permissive|httpof REST sync edges to sibling contexts (this context has none today) and anything that is not the database or the broker.- A Schemathesis contract job: this repository has none (
ci.ymland theMakefilehave no contract, Schemathesis or compose-boot job), so none was moved or invented. - Creating topics: infra owns them; the service still relies on broker auto-creation.
Addendum 2026-11-13: current state
Decisions 1 and 2 name four consumers and four consumer groups. cmd/api now starts five: ADR 0012 added the pack-level consumer (PACK_LEVEL_MODE, PACK_LEVEL_CONSUMER_GROUP, cmd/api/wire_kafka.go consumerSpecs), so PACK_LEVEL_CONSUMER_GROUP is mandatory too and all five consumers always start.