0042. Postgres and Kafka are the only runtime
Status
Accepted (2026-10-20). Supersedes the optional-runtime parts of
ADR 0017 (direct, outbox-less Kafka publishing
and the independent EVENT_PUBLISHER / DATABASE_URL toggles) and of the
consumer ADRs (0030,
0034,
0035,
0037), whose consumers were
"off" unless a mode or a group id was set. No schema or event contract changes.
Context
Until now the binaries could boot in several shapes: no DATABASE_URL meant
in-memory repositories, no EVENT_PUBLISHER meant a log-only publisher,
EVENT_PUBLISHER=kafka without a database meant direct publishing with no
outbox, LOCATION_LOOKUP_MODE unset meant a lookup that answered "unknown" for
every bin, and each of the four Kafka consumers started only when its mode or
group id was set. Each shape was a way to run green without the infrastructure
the service exists to use:
- Deployments that look healthy and do nothing. A pod with the log publisher or a consumer left off passes every probe while no event leaves and no command arrives.
- Tests that cannot see real-database failures. The in-memory adapters
accept text Postgres rejects (a NUL byte aborts the surrounding transaction,
SQLSTATE 22021 then 25P02), so a hostile request was a 200 in tests and a 500
in production. The Schemathesis
contractjob ran against that in-memory boot, so it could not see it either, and the OpenAPI document declaredIdempotency-Keyoptional only because that boot did not enforce it.
On 2026-10-19 the fleet decided that a service whose design needs Postgres and Kafka runs on Postgres and Kafka, and says so at boot.
Decision
Postgres and Kafka are the only runtime for inventory-storage.
- Mandatory configuration.
DATABASE_URL,KAFKA_BROKERS(nolocalhost:9092default),LOCATION_LOOKUP_MODEand the four consumer-group ids (TRANSFER_ALLOCATION_CONSUMER_GROUP,PRODUCT_MASTER_CONSUMER_GROUP,INBOUND_RECEIPT_CONSUMER_GROUP,TASK_COMPLETED_CONSUMER_GROUP) must be set.loadConfigvalidates everything before telemetry, the listener or any dial, and every problem is an error that names the variable. A restarted pod resumes from its committed offsets because the group ids are stable. - No in-memory mode, no log publisher, no direct publishing. Events always
leave through the transactional outbox. The
memoryadapters and the log publisher stay in the tree as test doubles for unit and BDD tests; nocmd/binary imports them (sensor:TestRuntimeBinaryHasNoInMemoryAdapters). EVENT_PUBLISHER,TRANSFER_ALLOCATION_CONSUMER_MODEandTASK_COMPLETED_CONSUMER_MODEare kept only as guards: unset orkafkais the single runtime, any other value (log,off) is a boot error naming the variable.warehouse-infrastill sets them, so they cannot be removed yet.LOCATION_LOOKUP_MODEiskafkaorhttp. Unset andpermissiveare refused: a lookup that answers "unknown" for every bin validates no location at all.httpadditionally needsFACILITY_LAYOUT_BASE_URL.- Always on. The outbox relay and the four consumers (transfer allocation,
product-master classification, inbound-receiving receipts,
TaskCompletedconfirm-pick) always run. - A dead worker ends the process. A consumer that returns for any reason
other than shutdown is reported to
run, which drains (readiness flips first, then HTTP, then the consumers) and returns the error, so the process exits non-zero and the orchestrator restarts it.run(ctx)takes the signal context frommain; the consumers run on a context detached from that cancellation so the shutdown order is unchanged. /readyzis the drain gate, a Postgres ping and a Kafka broker-metadata request. While a dependency is down it answers 503application/problem+jsonof typedependency-unavailable, naming the dependency. Topics are never checked, because the relay's writers auto-create their own. The verdict is cached for three seconds and is detached from the caller's cancellation./healthzstays liveness only. The projector's admin port gained the same/readyz(its own Postgres and Kafka).- A NUL byte never reaches Postgres: 404 in the request path, 400 in the
query string or the body (
rejectNUL, the first middleware). Idempotency-Keyisrequired: trueinapis/openapi.yaml. The middleware already answered 400idempotency-key-requiredin every deployment; the document now says what the service does.
Consequences
- Local runs need both services. The quickstart and the configuration reference describe only this runtime.
- A deployment that forgets Postgres or Kafka fails loudly: the process exits at boot, and the Helm chart refuses to render without a database, a broker list, a real publisher, a lookup mode and the four group ids.
- Tests that need real behaviour run on testcontainers
(
TestRunOnRealPostgresAndKafka); fast unit and BDD tests keep the doubles. - The
contractjob runs Schemathesis against apostgres:16and aconfluentinc/confluent-localservice container, with a hooks file that gives every request a freshIdempotency-Key. - A dependency outage takes the pod out of the Service (503 on
/readyz) instead of being invisible. The pod is not restarted:/healthzis independent.
What changed per binary
| Binary | Before | Now |
|---|---|---|
cmd/inventory | memory without DATABASE_URL; log publisher without EVENT_PUBLISHER; consumers and relay opt-in; permissive location lookup by default | DATABASE_URL, KAFKA_BROKERS, LOCATION_LOOKUP_MODE and four group ids mandatory; outbox, relay and all consumers always on; dead consumer exits non-zero; /readyz checks Postgres and Kafka |
cmd/mcp | memory without DATABASE_URL; log publisher by default | DATABASE_URL mandatory; always publishes through the outbox (the relay stays in cmd/inventory, so it still needs no broker) |
cmd/inventory-projector | KAFKA_BROKERS defaulted to localhost:9092; consumer death only logged | KAFKA_BROKERS and ANALYTICS_DATABASE_URL mandatory; exits non-zero when its consumer dies; /readyz |
cmd/inventory-reports | already required ANALYTICS_DATABASE_URL and uses a read-only pool | unchanged |
Deliberately out of scope
Recorded here so they are not mistaken for done:
LOCATION_LOOKUP_MODE=http(the synchronous REST call to facility-layout behind a circuit breaker) is unchanged. It is about how this service treats a sibling context over REST, not about Postgres or Kafka, and it stays as the documented rollback forkafka. Follow-up: decide the same question for the REST sync edges fleet-wide.cmd/mcphas no/readyz. It never dials Kafka and holds only a pool, so its probes stay on/healthz.- Readiness probe overrides in
warehouse-infra. The chart default points thereadinessProbeat/readyz, buthelm-values/inventory-storage.yamlondevelopoverrides it to/healthz(checked 2026-10-20), so a broker outage will not remove the pod from the Service until that override is dropped. Tracked as one fleet-wide infrastructure change. - Telemetry shutdown delay. With no reachable OTLP collector, shutdown waits about 5 s for the exporter to give up. It never blocks boot.