Skip to main content

Configuration

slotting-optimization ships five binaries, cmd/api, cmd/mcp, cmd/a2a, cmd/slotting-projector and cmd/slotting-reports, and all five are configured only through environment variables (one table per binary below). There is no config file and no flag. Every variable below is read in cmd/api/main.go unless the Source column says otherwise, and the list is complete: it comes from every os.Getenv / getenv call in cmd/ and internal/ outside _test.go files.

In the Helm chart every cmd/api variable has a config.* (or kafka.*, otel.*, database.*, environment) value, is rendered as explicit env on the api Deployment and is also in the chart ConfigMap, which the api Deployment mounts with envFrom (explicit env wins for the same key). charts/slotting-optimization/tests/render_test.sh (CI job chart-tests) reads the os.Getenv / getenv literals of cmd/api/main.go, cmd/mcp/main.go, cmd/slotting-projector/main.go and cmd/slotting-reports/main.go and fails when the matching Deployment does not render one of them, and when the ConfigMap has a key no binary reads.

cmd/api​

Server, logging and telemetry​

VariableDefaultRequiredMeaningSource
HTTP_ADDR:8080noListen address of the REST API, /healthz, /readyz and /metrics. ReadHeaderTimeout is fixed at 5 s.cmd/api/main.go (run)
LOG_LEVELinfonodebug, info, warn (or warning, accepted like warn fleet-wide) or error (case-insensitive). Any other value falls back to info silently. cmd/mcp parses it the same way. Logs are JSON lines on stdout (log/slog).cmd/api/main.go (newLogger)
SERVICE_VERSIONdevnoOTel resource attribute service.version.cmd/api/main.go (setupTelemetry)
ENVIRONMENTlocalnoOTel resource attribute deployment.environment.name.internal/adapters/outbound/telemetry/telemetry.go (Environment)
OTEL_EXPORTER_OTLP_ENDPOINTlocalhost:4317noOTLP/gRPC endpoint (host:port, insecure) for traces and metrics. The exporters connect lazily: no Collector means telemetry is dropped, never a failed boot.cmd/api/main.go, telemetry.DefaultOTLPEndpoint
CORS_ALLOWED_ORIGINShttp://localhost:5173noComma-separated origins allowed by the CORS middleware. Methods GET and POST; headers Accept, Content-Type, Idempotency-Key; no credentials.internal/adapters/inbound/http/server.go (corsAllowedOrigins)
SHUTDOWN_DRAIN_DELAY5snoHow long the process waits after flipping /readyz to 503 before it stops accepting connections. Go duration; 0 disables the wait; a negative or unparsable value logs ignoring invalid SHUTDOWN_DRAIN_DELAY and uses 5 s.cmd/api/main.go (shutdownDrainDelay)

Database​

VariableDefaultRequiredMeaningSource
DATABASE_URLnoneyesPostgres DSN of the pgx pool. There is no in-memory mode (ADR 0011): unset, the process exits at boot with DATABASE_URL is required: this context runs on real Postgres, there is no in-memory mode, before the listener binds. Set, the process runs the embedded migrations, opens a pool (MaxConns = 10, statement_timeout = 5s) and pings it; failure after the retry budget exits the process.cmd/api/main.go (loadRuntime, buildAdapters), internal/adapters/outbound/postgres/pool.go
MIGRATIONS_DATABASE_URLvalue of DATABASE_URLnoDSN used only for the boot migrations. Point it at a direct (non-PgBouncer) connection: golang-migrate takes a Postgres advisory lock that does not survive transaction pooling.cmd/api/main.go (migrationsDatabaseURL)

Planning​

VariableDefaultRequiredMeaningSource
DEMAND_SITE_IDunsetnoTwo effects. (1) It is the default site of POST /slot-plans, GET /forward-slots and GET /sku-velocity when the request names none. (2) The demand consumer drops SiteSkuDemandChanged lines of every other site (outcome ignored).cmd/api/main.go (configFromEnv), usecases.ApplyDemandChanged.OnlySite
DEFAULT_SITE_IDunsetnoDefault site used only when DEMAND_SITE_ID is unset. It does not filter demand. With neither set, a request without siteId is 400 invalid-site-id (ErrNoSite).cmd/api/main.go (configFromEnv)
LOOKBACK_DAYS28noDemand window, in days, of a plan whose request has no lookbackDays. Integer 1 to 365; anything else logs invalid LOOKBACK_DAYS; using the default and uses 28. It does not change the default windowDays of GET /sku-velocity, which is always 28.cmd/api/main.go (parseLookbackDays), usecases.DefaultLookbackDays
FORWARD_ZONE_CODESFWDnoComma-separated zone codes whose active Storage slots are forward pick slots. Blank entries are dropped; an empty list means FWD.cmd/api/main.go (parseZoneCodes), postgres.SlotCatalogue.ForwardSlots

Kafka: publishing​

VariableDefaultRequiredMeaningSource
EVENT_PUBLISHERkafkanoKept because the chart and warehouse-infra set it. The only value is kafka (the outbox relay writes to warehouse.slotting-optimization.events, always on). log refuses to boot (EVENT_PUBLISHER=log is not supported: this context publishes to real Kafka), any other value too (EVENT_PUBLISHER: unknown value ... (want kafka)).cmd/api/main.go (parsePublisherMode, startOutboxRelay)
KAFKA_BROKERSnoneyesComma-separated bootstrap brokers, shared by the relay writer, the five readers, the five DLQ writers and the /readyz broker check. Unset exits at boot with KAFKA_BROKERS is required: this context runs on real Kafka (outbox relay, consumers, /readyz). The fleet broker is reachable at localhost:9092 from a laptop.cmd/api/main.go (loadRuntime, startConsumers, startOutboxRelay)
OUTBOX_RELAY_INTERVAL1snoSleep between relay passes that did not fill a batch of 100 rows. Go duration (500ms) or plain seconds (0.5); invalid or non-positive logs invalid OUTBOX_RELAY_INTERVAL; using the default.cmd/api/main.go (parseRelayInterval), outbox.DefaultInterval
OUTBOX_MAX_ATTEMPTS20noHow many times one outbox row may fail before the relay excludes it from claims (ADR 0008), so a poison row cannot block every row behind it forever. The excluded row stays in outbox_events with attempts and last_error; the failure that reaches the cap logs one ERROR (outbox relay: row reached the attempt cap ...). 0 = unlimited (the old behaviour); a negative or non-integer value logs invalid OUTBOX_MAX_ATTEMPTS; using the default and uses 20. Re-arm a row with UPDATE outbox_events SET attempts = 0 WHERE id = ... (Runbook). Chart value config.outboxMaxAttempts.cmd/api/main.go (outboxMaxAttempts), outbox.DefaultMaxAttempts

Kafka: consumers​

Each local copy has its own mode variable and consumer group. All five consumers always run (ADR 0011). The mode names are kept because the chart and warehouse-infra set them, but the only value is kafka (also the default when unset): permissive and off exit at boot with <MODE>=permissive is not supported: this context runs on real Kafka, an unknown value with <MODE>: unknown mode "x" (want kafka). A missing group exits at boot with <GROUP> is required: the <MODE> consumer always runs on real Kafka. Group ids are never hard-coded (TestKafkaConsumerGroupNeverHardcodedInline).

VariableDefaultRequiredMeaningSource
DEMAND_MODEkafkanoThe demand consumer on warehouse.order-management.events. Only kafka.cmd/api/main.go (consumerSpecs, parseConsumerMode)
DEMAND_CONSUMER_GROUPnoneyesConsumer group id of the demand consumer.cmd/api/main.go (loadRuntime)
PRODUCT_MODEkafkanoThe product consumer on warehouse.product-master.events. Only kafka.cmd/api/main.go (consumerSpecs, parseConsumerMode)
PRODUCT_CONSUMER_GROUPnoneyesConsumer group id of the product consumer.cmd/api/main.go (loadRuntime)
LAYOUT_MODEkafkanoThe layout consumer on warehouse.facility.events. Only kafka.cmd/api/main.go (consumerSpecs, parseConsumerMode)
LAYOUT_CONSUMER_GROUPnoneyesConsumer group id of the layout consumer.cmd/api/main.go (loadRuntime)
RELOCATION_MODEkafkanoThe StockRelocated consumer on warehouse.inventory.events: the execution progress of the slot plans (ADR 0010). Only kafka. Chart value config.relocationMode.cmd/api/main.go (consumerSpecs, parseConsumerMode)
RELOCATION_CONSUMER_GROUPnoneyesConsumer group id of the StockRelocated consumer (e.g. slotting-optimization-relocation). Chart value config.relocationConsumerGroup.cmd/api/main.go (loadRuntime)
PACK_LEVEL_MODEkafkanoThe pack-level consumer on warehouse.product-master.events: ProductPackLevelDeclared, ProductPackLevelRetired and ProductPackLevelMeasured feed the local pack-level view (ADR 0012). Only kafka. Chart value config.packLevelMode.cmd/api/main.go (consumerSpecs, parseConsumerMode)
PACK_LEVEL_CONSUMER_GROUPnoneyesConsumer group id of the pack-level consumer. Chart value config.packLevelConsumerGroup.cmd/api/main.go (loadRuntime)

Readiness and worker failure​

/healthz is liveness only. /readyz is 200 only while the drain gate is open and Postgres answers a ping and a Kafka broker answers a metadata request with a topic list (an empty list is healthy: the service never requires topics, the writer auto-creates them); otherwise 503 dependency-unavailable naming postgres and/or kafka. The verdict is cached for 3 s and a check is bounded at 2 s. When the outbox relay or a consumer returns on its own (for example after the broker went away), the process logs <worker> stopped unexpectedly: exiting so the orchestrator restarts the service and exits non-zero, so the pod restarts instead of staying alive with a dead worker.

cmd/mcp​

The read-only MCP server (ADR 0005). It runs no relay and no consumer and never dials Kafka. Chart: mcp.enabled, mcp.httpAddr; the rest is shared with the api values.

VariableDefaultRequiredMeaningSource
MCP_ADDR:8090noListen address of the Streamable HTTP MCP endpoint and GET /healthz.cmd/mcp/main.go (run)
DATABASE_URLnoneyesAs for cmd/api: unset exits at boot (DATABASE_URL is required: this context runs on real Postgres, there is no in-memory mode). It reads the same Postgres as cmd/api.cmd/mcp/main.go (buildDeps)
MIGRATIONS_DATABASE_URLDATABASE_URLnoAs for cmd/api: the embedded migrations run before the pgx pool opens.cmd/mcp/main.go (buildDeps)
DEMAND_SITE_ID, DEFAULT_SITE_IDunsetnoThe site get_forward_slots and get_sku_velocity default to (DEMAND_SITE_ID, else DEFAULT_SITE_ID), matching cmd/api.cmd/mcp/main.go (defaultSite)
LOG_LEVEL, SERVICE_VERSION, ENVIRONMENT, OTEL_EXPORTER_OTLP_ENDPOINTas for cmd/apinoLogging and telemetry, parsed the same way.cmd/mcp/main.go, telemetry.go

cmd/a2a​

The read-only A2A agent (ADR 0013), the same read surface as cmd/mcp as an Agent2Agent agent. It runs no relay and no consumer and never dials Kafka. Chart: a2a.enabled, a2a.httpAddr, a2a.agentUrl; the rest is shared with the api values.

VariableDefaultRequiredMeaningSource
A2A_AGENT_URLnoneyesAbsolute http(s) URL of the JSON-RPC endpoint, advertised on the Agent Card. Unset, relative or schemeless exits at boot naming the variable. The chart defaults it to http://<release>-a2a.<ns>.svc.cluster.local:8093/ (a2a.agentUrl overrides).cmd/a2a/main.go (loadConfig)
A2A_ADDR:8093noListen address of the JSON-RPC endpoint (/ and /a2a), the Agent Card (/.well-known/agent-card.json) and GET /healthz.cmd/a2a/main.go (run)
DATABASE_URLnoneyesAs for cmd/mcp: unset exits at boot. It reads the same Postgres as cmd/api.cmd/a2a/main.go (loadConfig)
MIGRATIONS_DATABASE_URLDATABASE_URLnoAs for cmd/api: the embedded migrations run before the pgx pool opens.cmd/a2a/main.go (buildDeps)
DEMAND_SITE_ID, DEFAULT_SITE_IDunsetnoThe site forward_slot_map defaults to (DEMAND_SITE_ID, else DEFAULT_SITE_ID), matching cmd/api.cmd/a2a/main.go (defaultSite)
LOG_LEVEL, SERVICE_VERSION, ENVIRONMENT, OTEL_EXPORTER_OTLP_ENDPOINTas for cmd/apinoLogging and telemetry, parsed the same way.cmd/a2a/main.go, telemetry.go

cmd/slotting-projector​

The analytics writer (ADR 0006). It opens only the analytical database and Kafka, never the OLTP database. Chart: analytics.enabled (default false), analytics.url or analytics.existingSecret / analytics.existingSecretKey (the chart refuses analytics.enabled without one of them), analytics.consumerGroup, analytics.projector.adminAddr; KAFKA_BROKERS comes from kafka.brokers, LOG_LEVEL from config.logLevel.

VariableDefaultRequiredMeaningSource
ANALYTICS_DATABASE_URLnoneyesDIRECT (non-PgBouncer) DSN of the analytical database. The projector runs the embedded analytics/migrations through it (5 boot-retry attempts), then opens its writer pool (MaxConns = 5, statement_timeout = 10s). Unset exits at boot with ANALYTICS_DATABASE_URL is required: the projector writes only to the analytical database.cmd/slotting-projector/main.go (loadConfig, openAnalyticsPool), analyticsstore/pool.go
KAFKA_BROKERSnoneyesComma-separated brokers of the analytics reader and its DLQ writer. Unset exits with KAFKA_BROKERS is required: the projector consumes the analytics topic. The reader dials lazily, so a broker outage does not fail the boot.cmd/slotting-projector/main.go (loadConfig)
ANALYTICS_CONSUMER_GROUPslotting-optimization-analyticsnoConsumer group on warehouse.slotting-optimization.analytics. A new group starts at the first retained offset: that is the backfill / rebuild.cmd/slotting-projector/main.go (defaultConsumerGroup)
ADMIN_ADDR:8091noListen address of GET /healthz and GET /readyz (no other route).cmd/slotting-projector/main.go (loadConfig)
LOG_LEVELinfonoAs for cmd/api.cmd/slotting-projector/main.go (newLogger)
OTEL_EXPORTER_OTLP_ENDPOINTlocalhost:4317noAs for cmd/api; service.name is slotting-optimization-projector.cmd/slotting-projector/main.go (setupTelemetry)
SERVICE_VERSION, ENVIRONMENTdev, localnoOTel resource attributes, as for cmd/api.cmd/slotting-projector/main.go, telemetry.go

cmd/slotting-reports​

The read-only reports binary (ADR 0006). It opens only the analytical database, through a read-only pool, and never Kafka. Chart: the same analytics.* DSN values as the projector, analytics.reports.httpAddr, analytics.reports.service.port (default 80, target 8092).

VariableDefaultRequiredMeaningSource
ANALYTICS_DATABASE_URLnoneyesDSN of the analytical database, ideally a read-only role. The pool sets default_transaction_read_only = on, MaxConns = 5, statement_timeout = 15s; the first ping is boot-retried. Unset exits with ANALYTICS_DATABASE_URL is required: the reports are served from the analytical database. warehouse-infra's slotting-optimization-analytics-db Secret holds the same direct DSN under ANALYTICS_DATABASE_URL and ANALYTICS_READER_DATABASE_URL; the chart reads only ANALYTICS_DATABASE_URL, so the reports run as the projector's role, made read-only by the pool (ADR 0006 names a single analytics DSN).cmd/slotting-reports/main.go (run), analyticsstore/pool.go (NewReadOnlyPool)
HTTP_ADDR:8092noListen address of /reports/slot-plan-funnel, /reports/freshness and /healthz.cmd/slotting-reports/main.go (run)
LOG_LEVELinfonoAs for cmd/api.cmd/slotting-reports/main.go (newLogger)
OTEL_EXPORTER_OTLP_ENDPOINTlocalhost:4317noAs for cmd/api; service.name is slotting-optimization-reports.cmd/slotting-reports/main.go (run)
SERVICE_VERSION, ENVIRONMENTdev, localnoOTel resource attributes, as for cmd/api.cmd/slotting-reports/main.go, telemetry.go

Fixed values (not configurable)​

These are constants in code; changing them is a code change.

ValueConstantSource
HTTP graceful drain budget 10 s; consumer and relay drain 10 s each; telemetry flush 5 sshutdownTimeout, workerDrainTimeoutcmd/api/main.go
Projector and reports drain 10 sshutdownTimeoutcmd/slotting-projector/main.go, cmd/slotting-reports/main.go
Analytical pools: projector MaxConns = 5, statement_timeout = 10s; reports MaxConns = 5, statement_timeout = 15s, read-onlyanalyticsstore.MaxConns, StatementTimeout, ReportsMaxConns, ReportsStatementTimeoutinternal/adapters/outbound/analyticsstore/pool.go
Report range: default 30 days ending now, at most 366 days; granularity day onlyreport.DefaultWindow, report.MaxWindow, report.GranularityDayinternal/analytics/report/range.go
Boot retry: 5 attempts with 1 s, 2 s, 4 s, 8 s waits (15 s of backoff in total, no wait after the last attempt) for the migrations and the first pingbootretry.Retries, bootretry.Delayinternal/bootretry/bootretry.go
Pool: MaxConns = 10, statement_timeout = 5spostgres.MaxConns, postgres.StatementTimeoutinternal/adapters/outbound/postgres/pool.go
Relay batch 100 rowsoutbox.DefaultBatchSizeinternal/adapters/outbound/outbox/relay.go
Consumer retry: 200 ms doubling to 5 s, 5 handling attempts, then <topic>.dlqDefaultRetryInitial, DefaultRetryMax, domainMaxHandlerAttemptsinternal/adapters/inbound/kafka/kafka.go, deadletter.go
Projector consumer: a transient failure retries the same message forever (200 ms doubling to 5 s); a deterministic failure is dead-lettered at onceAnalyticsConsumer.Run (no maxAttempts)internal/adapters/inbound/kafka/analytics_consumer.go
ABC thresholds 80 % / 95 % of picksplanning.DefaultParametersinternal/domain/planning/planner.go
Request body limit 64 KiBmaxBodyBytesinternal/adapters/inbound/http/response.go
OTLP metric export every 30 smetricExportIntervalinternal/adapters/outbound/telemetry/telemetry.go

Typical profiles​

ProfileVariables
Unit tests, BDDnothing: they use the in-memory test doubles directly and never boot the binary
Local run (docker compose up -d, Quickstart)DATABASE_URL, KAFKA_BROKERS, the five *_CONSUMER_GROUP, and DEFAULT_SITE_ID=WH1 to omit siteId
Local analytics read side (Quickstart)ANALYTICS_DATABASE_URL (a second database), KAFKA_BROKERS and a *-local ANALYTICS_CONSUMER_GROUP for the projector; ANALYTICS_DATABASE_URL for the reports
A cluster deploymenteverything above with real DSNs and brokers, plus MIGRATIONS_DATABASE_URL when DATABASE_URL goes through a pooler, OTEL_EXPORTER_OTLP_ENDPOINT, SERVICE_VERSION, ENVIRONMENT and CORS_ALLOWED_ORIGINS, all set by charts/slotting-optimization from its values; the chart refuses to render without database.*, kafka.brokers and the five consumer groups, and without an analytics DSN source when analytics.enabled (Runbook). warehouse-infra sets mcp.enabled: true and analytics.enabled: true with analytics.existingSecret: slotting-optimization-analytics-db.