ADR 0010: Postgres and Kafka are the only runtime
Status
Accepted (2026-10-19). Supersedes the in-memory fallback, the log sink and the
optional relay that ADR 0005 and the first
composition roots of cmd/api and cmd/mcp allowed. Fleet decision
"everything must use real database and broker"; product-master is the second
context migrated, after pick-face-replenishment (its ADR 0006). No migration,
no contract change: REST, MCP and the CloudEvents envelope
(ADR 0004) are unchanged;
only the readiness of /readyz grows.
Context
Until now the runtime binaries could start in states that cannot serve the cluster, and did so silently:
cmd/apiwithoutDATABASE_URLloggedDATABASE_URL not configured; using in-memory adaptersand served REST on a repository, an outbox and a processed-event store that vanish on restart.cmd/apiwithoutEVENT_PUBLISHER=kafkarelayed the outbox to a log sink: rows were marked published and nothing reachedwarehouse.product-master.eventsor the analytics topic.KAFKA_BROKERSwas optional.cmd/mcpwithoutDATABASE_URLansweredproduct-not-foundfor every SKU from its own empty in-memory repository.- The projector defaulted its consumer group.
/readyzwas only a drain gate: it said "ready" while Postgres or Kafka was unreachable, so a pod without its dependencies took traffic.
The chart and the troubleshooting guide documented these fallbacks as normal states ("data disappears on every restart", "events logged, not sent"). A fallback that works makes a mis-set environment look like a healthy deployment.
Decision
- One runtime.
cmd/apiandcmd/mcprun on real Postgres;cmd/apiandcmd/product-projectorrun on real Kafka. There is no in-memory mode, no log sink, no optional relay and no*_MODEswitch. - Missing configuration is a boot error that names the variable, raised
before any listener binds, and never a default:
DATABASE_URL is required: this context runs on real Postgres,KAFKA_BROKERS is required: this context runs on real Kafka,ANALYTICS_CONSUMER_GROUP is required.EVENT_PUBLISHERstays only because the chart and warehouse-infra set it: empty andkafkaare accepted,logand anything else stop the boot. - The composition root builds real adapters only.
cmd/apiis split intoconfig.go(environment to a validated config),adapters.go(Postgres repositories, unit of work, outbox),relay.go(the outbox relay on the Kafka sink, which is refused without a store or brokers) andmain.go. Hexagonal architecture is kept: thememoryadapters stay as test doubles for unit and BDD tests and are never imported by a binary. /readyztells the truth. It is200only while the drain gate is open AND Postgres answers a ping AND a Kafka broker answers. Otherwise503({"status":"not_ready"}while draining; aproblem+jsonof typedependency-unavailablenamingpostgresorkafkawhen a dependency fails). The verdict is cached 3 s and one round is bounded to 2 s, so probe traffic cannot hammer the database or the broker; a cancelled caller does not poison the cached verdict./healthzstays a pure liveness check.- Readiness checks the broker, not the topics. The broker auto-creates
topics on the first write (fleet convention,
warehouse-infraterraform/kafka.tf) 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. The check dials a fresh connection per call and asks for the broker list; kafka-go'sClient.Metadatais served from the transport's cached layout after the first answer and would not notice a broker going away. - A sensor keeps it true.
TestRuntimeBinaryHasNoInMemoryAdapters(internal/architecture) fails when any non-test file undercmd/**importsinternal/adapters/outbound/memory, and requirescmd/to hold real binaries.TestNoGoFilesAtRepoRootkeeps the repository root free of Go files, so the godog runner and the analytics end-to-end test live infeatures/. - The deployment mirrors it. The chart fails the render, naming the value,
without
database.url/database.existingSecretorkafka.brokers(no default), withconfig.eventPublisherother thankafka, withkafka.enabled=false, with a*_MODEentry inextraEnv, with a grace period under 25 s, and with analytics enabled but no analytical DSN source or consumer group.KAFKA_BROKERSis always rendered.kafka.enabledis still accepted (warehouse-infra sets it totrue) but is no longer a switch.
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/apineeds a Postgres and a Kafka broker (the kind cluster, or any containers you start). Fast feedback stays in unit and BDD tests over the memory doubles. - A broker outage now takes the api pods out of the Service (readiness
503), not out of the node: liveness is unaffected, so nothing restarts. Writes that were accepted stay in the transactional outbox and are relayed when the broker returns (ADR 0007). If every api pod is not-ready at once REST write traffic stops until a dependency recovers; the readiness probe tolerates three failures (failureThreshold: 3,timeoutSeconds: 3) so a one-off blip does not flap. - The in-memory outbox no longer injects the trace context in any binary path (ADR 0009 point 5 is now unreachable outside tests).
- Tests:
TestRunOnRealPostgresAndKafka(cmd/api/e2e_integration_test.go, testcontainers) boots the realrun(), drives REST, asserts the rows in Postgres, the CloudEvents on both topics, replay idempotency, an in-process restart, and/readyzfollowing the dependencies (green with no topic,503naming the dependency when it goes away).TestBrokerCheck_RealKafka_NeedsNoTopicAndCreatesNoneproves the broker check needs and creates no topic. Unit tests cover every boot error (bootconfig_test.go,main_test.go, the mcp and projector mains).