39. 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 fan-out and the "relay only with
EVENT_PUBLISHER=kafka" rule that
ADR 0009,
ADR 0018 and
ADR 0019 allowed. Fleet decision of
2026-10-17, "everything must use real database and broker"; facility-layout
follows product-master (their ADR 0010) and workforce-management (their ADR
0038). No migration; REST, MCP and the CloudEvents envelope
(ADR 0024) are unchanged. One
contract detail follows from it: Idempotency-Key is now required: true in
apis/openapi.yaml, because the Postgres-backed check can no longer be absent.
Context
The binaries could start in states that cannot serve the cluster, and did so silently:
cmd/facilityandcmd/mcpwithoutDATABASE_URLloggeddatabase url not configured; using in-memory adaptersand served from their own empty in-memory repositories: data vanished on restart, the MCP server saw none of the API's data, and the Idempotency-Key check was skipped.EVENT_PUBLISHERdefaulted to the log publisher (and the chart default wasconfig.eventPublisher: "log"): no outbox row was written and nothing reachedwarehouse.facility.eventsorwarehouse.facility.analytics, while/readyzsaid ready. With Kafka but without a database the service published directly, outside any transaction.KAFKA_BROKERSdefaulted tolocalhost:9092.- The projector hard-coded its consumer group (
facility-analytics). /readyzwas only a drain gate: ready while Postgres or Kafka was unreachable.- 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/facilityandcmd/mcprun on real Postgres;cmd/facilityandcmd/facility-projectorrun on real Kafka; the projector andcmd/facility-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 always runs, fanning each event out to the integration topic and the analytics topic. - 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,ANALYTICS_DATABASE_URL,KAFKA_BROKERSandANALYTICS_CONSUMER_GROUPfor the projector (no default in the binary).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 for unit and BDD tests and are never imported by a binary. The wall clock and id source the binaries need moved tointernal/adapters/outbound/system. /readyztells the truth.cmd/facilityis200only while the drain gate is open AND Postgres answers a ping AND a Kafka broker answers; the projector's admin/readyzfollows its two dependencies andcmd/facility-reportspings its analytical Postgres. The verdict is cached a few seconds, bounded in time, and/healthzstays a pure liveness check.- Readiness checks the broker, not the topics. The broker auto-creates topics on the first write (fleet convention) and this service never creates topics through an admin API. A not-ready pod receives no traffic and so 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, andTestNoGoFilesAtRepoRootkeeps the repository root free of Go files: the four godog files moved from the root tofeatures/. - 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, with a grace period under 20 s, and with analytics enabled but no analytical DSN source oranalytics.projector.consumerGroup(defaultfacility-analytics, the group the projector has always used, so its committed offsets survive the rollout).KAFKA_BROKERSis always rendered.kafka.enabledis still accepted (warehouse-infra sets it totrue) but is no longer a switch.charts/facility-layout/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 carriespostgres:16andconfluentinc/confluent-local:7.6.1; the CIcontractjob uses the same two images as service containers andscripts/contract-test.shrequiresDATABASE_URLandKAFKA_BROKERS. The old in-memory boot seeded nothing, and the new boot starts on an empty database equally. A Schemathesis hook (scripts/contract_hooks.py) gives every request a freshIdempotency-Key, since a reused key with a different body is by design a422. - A NUL is a client error. The first CI run of the real-service contract
job found what the in-memory boot hid: a fuzzed JSON body with U+0000 in a
string reached a Postgres text parameter, which aborted the idempotency
transaction and surfaced as
500 internal-error(SQLSTATE 25P02).rejectNUL(internal/adapters/inbound/http/nul.go) now 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" and the rejection would otherwise read as "API rejected schema-compliant request"; the behaviour is pinned byTestRejectNULandTestNUL_IsAClientErrorAndDoesNotConsumeTheKey(real Postgres).
Consequences
- A mis-set environment fails at boot with a message that names the missing variable; it no longer degrades into a pod that is up, empty and silent.
- Local
go run ./cmd/facilityneeds a Postgres and a Kafka broker:docker compose up -d --waitprovides both. Fast feedback stays in unit and BDD tests over the memory doubles. - A broker outage takes the api pods out of the Service (readiness
503) where the probe is/readyz; liveness is unaffected, so nothing restarts. Writes that were accepted stay in the transactional outbox and are relayed when the broker returns (ADR 0018, ADR 0036). - Tests:
TestRunOnRealPostgresAndKafka(cmd/facility/e2e_integration_test.go, testcontainers) boots the realrun()with nothing but the deployment's environment, drives REST only, asserts the Postgres rows, the CloudEvents envelope byte for byte on both output topics,Idempotency-Keyreplay, an in-process restart (no loss, no duplicate) and/readyzfollowing the dependencies. Every boot error is a table test (cmd/facility/bootconfig_test.go,cmd/facility-projector/config_test.go,cmd/mcp/migrations_test.go).
Out of scope
facility-layout reads no *_MODE variable (it has no outbound REST sync
edge), so nothing of that kind is left behind here; the *_MODE switches that
exist in sibling contexts (for example LOCATION_ROLE_MODE and
TRAVEL_DISTANCE_MODE in the consumers of this service's REST API) are theirs
to retire. warehouse-infra's readiness probe still points at /healthz;
switching it to /readyz is an infra follow-up.