0037. Postgres and Kafka are the only runtime
Status
Accepted (2026-10-19). Supersedes the in-memory fallback, the log
publisher, the direct (non-outbox) Kafka publisher and the localhost:9092
default that ADR 0001,
ADR 0003,
ADR 0006,
ADR 0007,
ADR 0011 and
ADR 0025 allowed. Fleet decision of
2026-10-17, "everything must use real database and broker", following
product-master, workforce-management, facility-layout and labor-performance
(their ADR 0034). No data migration. The CloudEvents envelope
(ADR 0016), the topics and
every public event shape are unchanged. One REST contract detail follows:
Idempotency-Key is now required: true and /readyz is in
apis/openapi.yaml.
Context
The binaries could start in states that cannot serve the cluster, and did so silently:
cmd/pathmgmtandcmd/mcpwithoutDATABASE_URLserved from their own empty in-memory repositories: data vanished on restart, the MCP server saw none of the API's data, there was no outbox, no sweeper and no Idempotency-Key check.EVENT_PUBLISHERdefaulted to the log publisher: nothing reachedwarehouse.process-path-management.events(consumed by fulfillment-execution, wes-work-planning, workforce-management, order-management and network-fulfillment) or.analytics, while/readyzsaid ready. With Kafka but without a database the service published directly, outside any transaction.KAFKA_BROKERSdefaulted tolocalhost:9092incmd/pathmgmtandcmd/pathmgmt-projector, and the chart'skafka.enabled: falsedefault left it unset./readyzwas only a drain gate: ready while Postgres or Kafka was down.- The Schemathesis
contractjob booted the service in memory, so it tested a mode that is not deployed.
A fallback that works makes a mis-set environment look like a healthy deployment.
Decision
- One runtime.
cmd/pathmgmtandcmd/mcprun on real Postgres;cmd/pathmgmtandcmd/pathmgmt-projectorrun on real Kafka; the projector andcmd/pathmgmt-reportsrun on the analytical Postgres. There is no in-memory mode, no log sink and no direct publisher: events are written through the transactional outbox in the use case's transaction and the relay and the housekeeping sweeper always run. - Missing configuration is a boot error that names the variable, raised
before telemetry, any connection and the listener, every problem reported at
once:
DATABASE_URL is required: this context runs on real Postgres,KAFKA_BROKERS is required: this context runs on real Kafka.cmd/mcprequiresDATABASE_URL;cmd/pathmgmt-projectorrequiresANALYTICS_DATABASE_URLandKAFKA_BROKERS;cmd/pathmgmt-reportsalready requiredANALYTICS_DATABASE_URL.EVENT_PUBLISHERstays only because the chart and warehouse-infra set it: unset andkafkaare accepted,logand anything else stop the boot. - The composition roots build real adapters only. The
memoryadapters stay ininternal/adapters/outbound/memoryas test doubles and are never imported by a binary. The wall clock the binaries need moved tointernal/adapters/outbound/system. /readyztells the truth.cmd/pathmgmtanswers200only while the drain gate is open AND Postgres answers a ping AND a Kafka broker answers a metadata request. A failed dependency is503 dependency-unavailable(problem+json) naming it. The verdict is cached 3 s and bounded to 2 s;/healthzstays a pure liveness check.- Readiness checks the broker, not the topics. The metadata request names no topic, on a fresh connection each time; the broker auto-creates topics on the first write and this service never creates topics through an admin API. A not-ready pod receives no traffic and could never make the first write: requiring the topics would deadlock a cold cluster.
- Sensors keep it true.
TestRuntimeBinaryHasNoInMemoryAdapters(internal/architecture, withTestRuntimeBinarySensorBites) fails when a non-test file undercmd/**importsinternal/adapters/outbound/memory. - The deployment mirrors it. The chart fails the render, naming the value,
without
database.url/database.existingSecretorkafka.brokers, withconfig.eventPublisherother thankafka, withkafka.enabled=false, with anEVENT_PUBLISHERor*_MODEentry inextraEnv, and with a grace period under 20 s.KAFKA_BROKERSandDATABASE_URLare always rendered.kafka.enabledis still accepted (warehouse-infra sets it to'true') but is no longer a switch.charts/process-path-management/tests/warehouse-infra-values.yamlmirrors what warehouse-infra sets andrender_test.shrenders it, so infra needs no change. - The contract job runs the real service.
docker-compose.ymlnow carriesconfluentinc/confluent-local:7.6.1next topostgres:16; the CIcontractjob uses the same two images as service containers andscripts/contract-test.shrequiresDATABASE_URLandKAFKA_BROKERSand waits for/readyz. The contract job needs no catalogue data: it starts on an empty database exactly as the old in-memory boot did, and Schemathesis creates what it needs through the API. A Schemathesis hook (scripts/contract_hooks.py) gives every request that carries the header a freshIdempotency-Key, since a reused key with a different body is by design a422. - A NUL is a client error. A fuzzed U+0000 in a string reaches a Postgres
text parameter, which aborts the transaction (SQLSTATE 22021) and surfaces
as
500on the real runtime; the in-memory adapters never noticed (found by facility-layout's contract run).rejectNUL(internal/adapters/inbound/http/nul.go) answers a NUL in a body with400 malformed-request-bodybefore the Idempotency-Key middleware records anything, and a NUL in the path with404. The contract script passes--generation-allow-x00 false, because OpenAPI 3.0 cannot express "no U+0000"; the behaviour is pinned byTestRejectNULandTestNUL_IsAClientErrorAndDoesNotConsumeTheKey(real Postgres).
Consequences
- A mis-set environment fails at boot with a message that names the missing variable.
- Local
go run ./cmd/pathmgmtneeds Postgres and Kafka:docker compose up -d --wait postgres kafkaprovides both. Fast feedback stays in unit and BDD tests over the memory doubles. - A broker outage takes the api pods out of the Service where the readiness
probe is
/readyz; liveness is unaffected, so nothing restarts. Accepted writes stay in the outbox and are relayed when the broker returns (ADR 0003, ADR 0030). make seed-catalogueis unchanged: it appliescatalogue/paths.jsonto a RUNNING service over REST, so it now runs against a service on real Postgres + Kafka (the data survives restarts, which the in-memory service never gave it).- Tests:
TestRunOnRealPostgresAndKafka(cmd/pathmgmt/e2e_integration_test.go, testcontainers) boots the realrun()with nothing but the deployment's environment, drives REST only and asserts the Postgres rows, the outbox drain, the CloudEvents envelope on both topics,Idempotency-Keyreplay, a NUL body, an in-process restart and/readyzfollowing the dependencies. Every boot error is a table test (cmd/pathmgmt/bootconfig_test.go,cmd/pathmgmt-projector/config_test.go,cmd/mcp/wiring_test.go).
Out of scope
process-path-management makes no REST or MCP call to a sibling context
(ADR 0007), so no *_MODE switch exists
here. Left as follow-ups: the projector's admin listener answers /readyz
without checking its dependencies; cmd/pathmgmt-reports is unchanged.