0044. Postgres and Kafka are the only runtime
Status
Accepted (2026-10-19). Amends the "in-memory when DATABASE_URL is unset",
"EVENT_PUBLISHER=log is the default", "KAFKA_BROKERS enables the consumer"
and "permissive is the default" passages of
ADR 0014,
ADR 0035 and
ADR 0042; their decisions otherwise
stand. Mirrors product-master ADR 0010, workforce-management ADR 0038 and
facility-layout ADR 0039.
Context
The user's rule is final: everything must use a real database and a real broker. Until this change the shipped binaries still had an in-memory path:
DATABASE_URLunset selected the in-memory repositories (no idempotency middleware, no outbox, no housekeeper).EVENT_PUBLISHERdefaulted tolog;kafkawithout a database published directly to Kafka, bypassing the outbox.KAFKA_BROKERSwas optional and switched the integration-event consumer on.PRODUCT_CLASSIFICATION_MODEandREPLENISHMENT_MODEdefaulted topermissive, which consumed nothing;cmd/wes-projectordefaulted its broker tolocalhost:9092.cmd/mcphad its own in-memory work-pool and work-unit stores, so an MCP tool saw an empty world unlessDATABASE_URLwas set.
That is exactly the kind of configuration that hid defects. The first Schemathesis run on a real Postgres found two (below) that the in-memory boot could never produce.
Decision
- Mandatory environment, checked before anything is dialled or bound.
cmd/wesrefuses to boot, with an error that names the variable, whenDATABASE_URL,KAFKA_BROKERS,KAFKA_CONSUMER_GROUP,PRODUCT_CLASSIFICATION_CONSUMER_GROUPorREPLENISHMENT_CONSUMER_GROUPis missing or blank.cmd/mcprequiresDATABASE_URLandKAFKA_BROKERS;cmd/wes-projectorrequiresKAFKA_BROKERS(it already requiredANALYTICS_DATABASE_URL). - Kept variable names, narrowed values.
EVENT_PUBLISHER(the chart and warehouse-infra set it) accepts onlykafka;logand anything else is a boot error.PRODUCT_CLASSIFICATION_MODEandREPLENISHMENT_MODEdefault tokafka;permissive,off, the retiredhttpand any other value are boot errors naming the variable. - The outbox relay and every consumer are always on. Events leave only through the transactional outbox (ADR 0014); there is no log sink and no direct-to-Kafka path. A relay or consumer that dies on its own (not through shutdown) takes the process down with a non-zero exit, so the pod restarts instead of staying alive with dead consumers.
/readyzis real. It is503while draining, while Postgres does not answer a ping, or while no Kafka broker answers a metadata request. It never requires a topic (the writers auto-create theirs). Results are cached for 3s with a 2s bound per probe./healthzstays liveness.- Memory adapters are test doubles.
internal/adapters/outbound/memoryremains for unit tests; the wall clock the binaries need moved tointernal/adapters/outbound/system. The architecture testTestRuntimeBinaryHasNoInMemoryAdapters(with a bites test) fails when a non-test file undercmd/**imports the memory or log-events adapter packages or names the in-memory/permissive copies. - NUL and integer bounds are client errors. Postgres text cannot hold
U+0000: a
rejectNULmiddleware answers404for a NUL in the path and400 malformed-request-bodyfor a NUL in the body or query, before the idempotency middleware can record the key.PUT /paths/{pathId}/poolboundswipLimittoMaxWIPLimit(2147483647, the PostgresINTEGERmaximum); a larger value is400 invalid-wip-limit. - The idempotency check is always on, so
Idempotency-Keyisrequired: trueinapis/openapi.yamlon the resource-creating POST. - CI and the chart follow. The
contractjob runs Schemathesis against the realcmd/wesonpostgres:16andconfluentinc/confluent-local:7.6.1service containers (the Kafka container advertisesPLAINTEXT_HOST://localhost:<port>); a before-call hook gives every request a freshIdempotency-Key;--generation-allow-x00 false. The chart refuses to render withoutdatabase.*,kafka.brokersand every consumer group, and refusesEVENT_PUBLISHER,PRODUCT_CLASSIFICATION_MODEorREPLENISHMENT_MODEoverrides other thankafka.docker-compose.ymlnow brings up Postgres and a single-node Kafka for local runs.
Consequences
- A local run needs
docker compose up -d(Postgres + Kafka) and four environment variables set; there is no "try it with nothing" mode. The unit, BDD and architecture tests are unaffected (they use the memory doubles directly); the end-to-end test (cmd/wes/e2e_integration_test.go) boots the realrun(ctx)against testcontainers Postgres and Kafka and drives it only through REST and Kafka. - Two defects that the in-memory boot hid are fixed: a fuzzed NUL was a
500(SQLSTATE 22021, then 25P02), and awipLimitabove theINTEGERrange was a500from the Postgres write. - A deployment must provide every mandatory variable. warehouse-infra's current values for this service already do; the chart tests render them to prove it.
- Unknown limitations carried over from the fleet: a kafka-go group consumer
that starts before its topic exists may not pick the topic up when it appears
(see inbound-receiving ADR 0011), and the first outbox write to a
not-yet-created output topic can fail once with
Unknown Topic Or Partitionand succeed on the next pass. This ADR does not try to solve either.
Out of scope (follow-up)
The REST sync edges to sibling contexts keep their *_MODE:
TRAVEL_DISTANCE_MODE=permissive|http (facility-layout, ADR 0017) is
unchanged. PATH_CATALOGUE_SOURCE=file|kafka is a read-only configuration
cache, not state, and is unchanged. Neither is a database or a broker.