Skip to main content

Operations runbook

This page covers how facility-layout is deployed, what each process does at runtime, and the routine procedures an operator needs. Every fact here comes from charts/facility-layout/, cmd/*/main.go and the outbound adapters on develop. Environment variables are listed in Configuration.

Deployment shape​

There is one Helm chart, facility-layout (charts/facility-layout/Chart.yaml, chart 0.1.0). It deploys one image, iqvo/facility-layout, containing every binary under /app/, plus an optional frontend image. Every Deployment except the main one is disabled by default.

Deployment (name)Binary / commandEnabled byContainer portServiceProbes
<fullname> (component api)facility (image default entrypoint)alwayshttp 8080 (service.targetPort)<fullname> ClusterIP :80 → 8080startup /healthz (2s × 30), liveness /healthz, readiness /readyz
<fullname>-projector/app/facility-projectoranalytics.enabledadmin 8091nonestartup/liveness /healthz, readiness /readyz on admin
<fullname>-reports/app/facility-reportsanalytics.enabledhttp 8092<fullname>-reports ClusterIP :80 → 8092startup/liveness /healthz, readiness /readyz
<fullname>-mcp/app/mcpmcp.enabledhttp 8090<fullname>-mcp ClusterIP :8090 → 8090startup/liveness/readiness all /healthz
<fullname>-frontendnginx-unprivileged serving web/frontend.enabled8080ClusterIP :80 → 8080/healthz

terminationGracePeriodSeconds is 30 on the api and projector pods. North-south traffic comes in either through ingress (disabled by default) or through a Gateway API HTTPRoute (gatewayApi.enabled, ADR-0029). In the fleet, Kong (:8000) fronts the REST API. The exact path prefix is set in warehouse-infra, not in this chart. The frontend is reached through warehouse-infra's Nginx web gateway at /mfes/facility-layout/ and never through Kong. REST and MCP are unauthenticated (ADR-0015). MCP is reachable only from inside the cluster.

Source: cmd/facility/main.go, cmd/facility-projector/main.go, cmd/facility-reports/main.go, cmd/mcp/main.go, charts/facility-layout/templates/*.yaml.

Readiness: what /readyz waits for​

/readyz is the drain gate and a dependency check (ADR-0020, ADR 0039):

Binary/readyz returns 200 while
facilitythe process is not draining, Postgres answers a ping and a Kafka broker answers a topic-less metadata request (cmd/facility/main.go:23)
facility-projector (on admin)not draining, Postgres (analytical database) pings and a Kafka broker answers (newReadiness)
facility-reportsnot draining and the analytical Postgres pings (cmd/facility-reports/main.go:94-99)
mcpserves /healthz only, no /readyz

After SIGTERM it answers 503 {"status":"not_ready"}; while a dependency is down it answers 503 application/problem+json of type dependency-unavailable whose detail names the failing dependencies (internal/adapters/inbound/http/readiness.go). The verdict is cached for a short TTL, and topics are never checked (a broker with no topic is Ready). warehouse-infra helm-values/facility-layout.yaml carries no readinessProbe override on develop (the old /healthz override went away with #123), so the chart default applies and the pod is routed traffic only while /readyz is 200.

Dependency checks also run before the listener starts: migrations and a pool ping each run under boot retry (5 attempts with 1s, 2s, 4s and 8s backoff, 15s of waiting in total). The process exits non-zero if they still fail. So "the pod never becomes Ready" is either a crash-looping boot or a dependency that /readyz names: read the logs and curl /readyz.

The startup probe allows 60s (2s × 30) before liveness takes over, well past the boot retry budget: 15s of backoff (1+2+4+8) plus the duration of each of the 5 attempts.

Graceful shutdown order (ADR-0020)​

facility handles SIGTERM in this order:

  1. Readiness flips to not-ready.
  2. http.Server.Shutdown drains requests, with a 10s budget.
  3. The outbox relay context is cancelled. Shutdown waits, within the same 10s budget, for the in-flight pass to finish.
  4. The Kafka writers are closed.
  5. The pgx pool is closed.

The projector does the same with its consumer: it waits for the in-flight message to commit or dead-letter before the pool closes. Reports only drains HTTP. MCP drains HTTP with a 10s budget.

Migrations​

SchemaFilesRun byDSN
OLTPmigrations/0001_init … 0012_site_capability_heartbeat (tables sites, zones, aisles, location_types, placement_rules, location_slots, fixed_structures, cross_aisles, outbox_events, idempotency_keys; 0005 drops the legacy events table; 0008 adds the additive sites columns transfer_origin_enabled, transfer_destination_enabled, capability_revision and version, ADR-0035; 0009 adds sites.site_role (default UNSPECIFIED, CHECK of the 16 values) and runs the ONE-TIME backfill that maps the seeded names <CODE> - <Role words> (<city>) to a role, ADR-0037; 0010 adds the nullable outbox_events.headers holding the writing transaction's W3C trace context, ADR-0038; 0011 adds the nullable location_slots.handling_unit, ADR-0040; 0012 adds the nullable sites.capability_heartbeat_at, ADR-0041)both facility and mcp, at every boot, before the pool opensMIGRATIONS_DATABASE_URL, falling back to DATABASE_URL
Analyticalmigrations/analytics/0001_report (tables analytics_processed_events, analytics_consumed_events, catalog_growth_rollup)facility-projector only, at every bootANALYTICS_DATABASE_URL

Migrations use golang-migrate (internal/adapters/outbound/postgres/migrate.go). Its session-scoped advisory lock serialises replicas that boot at the same time. That only works over a direct connection, which is why MIGRATIONS_DATABASE_URL exists: PgBouncer in transaction-pooling mode breaks the lock, and the losing replicas crash-loop with pq: unnamed prepared statement does not exist (ADR-0023). The chart reads that key from the database Secret with optional: true. If the key is missing, migrations silently run against DATABASE_URL. There is no separate migration Job: a migration is applied when the first new pod boots. A failing migration therefore shows up as a crash-looping pod (see Troubleshooting).

Kafka​

There is one platform broker, reached in-cluster through kafka.brokers (mandatory, no default; ADR 0039) or locally at localhost:9092 (docker compose up -d --wait). Every message is a CloudEvents 1.0 event in structured content mode (ADR-0024, internal/adapters/kafka/cloudevents), with W3C trace context in the message headers. On the outbox path that context is the one stored with the row when it was written (outbox_events.headers, ADR-0038).

TopicDirectionProducer / consumerGroupKey
warehouse.facility.eventsproducefacility (outbox relay, or direct fan-out when there is no DB)n/aaggregate id. FacilityLayoutImported is keyed by its CloudEvents id (ADR-0032).
warehouse.facility.analyticsproduce + consumeproduced by facility, consumed by facility-projectorfacility-analyticssame as above
warehouse.facility.analytics.dlqproducefacility-projector DLQ writern/aoriginal message key

facility consumes nothing. It is a pure Open Host Service publisher, which is why the api HPA has no consumer-group concerns. Both topics carry every domain event the use cases raise. All writers use the Hash balancer (ADR-0021), AllowAutoTopicCreation and fleet durability settings (ADR-0031).

Outbox relay (ADR-0018)​

The relay always runs in facility (DATABASE_URL and KAFKA_BROKERS are mandatory, ADR 0039; there is no mode that turns it off). Each use case writes its aggregate and up to two outbox_events rows (one per topic) in a single transaction. A goroutine in facility then drains the table:

  • Each pass claims up to 100 unpublished rows ORDER BY id ... FOR UPDATE SKIP LOCKED, so overlapping pods during a rolling deploy never claim the same row.
  • Rows are sent in order. On success the row gets published_at = now(). On the first failure the pass stops, so a later event never overtakes an earlier one: the failing row gets attempts + 1 and last_error, the error outbox relay pass failed is logged, and the pass retries after OUTBOX_RELAY_INTERVAL.
  • Attempt cap (ADR-0036): once a row has failed OUTBOX_MAX_ATTEMPTS sends (default 20, 0 = unlimited) the relay logs it once at ERROR (outbox relay: row reached the attempt cap and is excluded from future claims; ..., with outbox_id, topic, event_type, key) and stops claiming it. Later rows, including rows with the same key, then overtake it: one poison row no longer blocks the relay forever, at the cost of per-key ordering for that row. The row stays in outbox_events (published_at IS NULL, attempts, last_error); the sweeper never deletes unpublished rows.
  • A full batch is followed immediately by another pass. An empty pass sleeps for the interval.
  • Delivery is at-least-once, so consumers must dedupe on the CloudEvents id.

An outbox row hit the attempt cap​

  1. Find excluded rows (replace 20 with the configured cap): SELECT id, topic, event_type, key, attempts, last_error FROM outbox_events WHERE published_at IS NULL AND attempts >= 20 ORDER BY id;
  2. Fix the cause named in last_error (broker message size limit, missing topic, ACL, ...).
  3. Re-arm the row: UPDATE outbox_events SET attempts = 0 WHERE id = <id>; The relay claims it on its next pass and sends it with the same CloudEvents id. Later rows with the same key may already have been delivered, so the consumer receives this event late.
  4. Do not delete the row unless you accept that downstream contexts never receive that event.

The chart's config.eventPublisher is kafka; log is refused at render time and by the binary at boot (ADR 0039), so a deployment can no longer end up writing no outbox rows and publishing nothing.

Analytics consumer and DLQ (ADR-0020, ADR-0030)​

facility-projector starts a new group at the earliest offset, so the read model replays the full topic. Each message works like this:

  • The message is decoded as a CloudEvent. Its type is matched exactly against the eight catalog-change types (SiteRegistered, ZoneRegistered, AisleRegistered, LocationTypeRegistered, PlacementRuleDefined, LocationSlotRegistered, LocationSlotDecommissioned, FacilityLayoutImported). Any other type is committed and ignored.
  • Duplicates are skipped through analytics_processed_events, keyed by the CloudEvents id.
  • A failure is retried in-process up to 3 attempts, with jittered backoff from 100ms up to 2s. After that the raw message is published to warehouse.facility.analytics.dlq with headers x-dlq-source-topic, x-dlq-error and x-dlq-failed-at, and the offset is committed.
  • A message that is not a valid CloudEvent is dead-lettered immediately, without retries.
  • A failure to commit or to write to the DLQ stops the consume loop: the error analytics consumer stopped is logged. The process keeps serving /healthz, but it no longer consumes until the pod restarts.

Site capability heartbeat (ADR-0041)​

network-inventory-planning treats a site-capability fact older than 10 minutes as stale, and SiteCapabilityChanged is raised only when a capability changes. So facility runs a heartbeat loop: at start and then every interval/5 it re-publishes, through the outbox, the current capability of every active site with a declared capability (capability_revision > 0) that was not heartbeated in the last SITE_CAPABILITY_HEARTBEAT_INTERVAL (default 5m, chart config.siteCapabilityHeartbeatInterval; 0s disables). Each heartbeat is a SiteCapabilityChanged with a new CloudEvents id, a fresh time and capability_revision + 1; the values are the current ones.

  • Replicas all run it; sites.capability_heartbeat_at plus the site version guard keep it to one heartbeat per site per interval. A lost race is not an error: the site is simply skipped.
  • Logs: site capability heartbeat (published, skipped) when it published, site capability heartbeat failed on error, site capability heartbeat disabled once at boot when the interval is 0.
  • A site NIP calls stale although the loop runs: check SELECT code, capability_revision, capability_heartbeat_at FROM sites WHERE capability_revision > 0; (a NULL or old capability_heartbeat_at on an active site means the loop is not publishing) and the outbox relay backlog. A decommissioned site is not heartbeated and ages out by design.

Housekeeping sweeper (ADR-0026)​

The sweeper runs inside facility whenever Postgres is configured. It sweeps once at start and then every HOUSEKEEPING_INTERVAL (default 1h). Each pass deletes, in batches of 1000:

  • idempotency_keys rows older than IDEMPOTENCY_KEY_TTL (24h);
  • published outbox_events rows older than OUTBOX_RETENTION (7d). Unpublished rows are never deleted.

A replay does not test the age of its row: the purge alone bounds the 24 hours (ADR-0046, follow-up). A refusal whose problem type is RETRYABLE (concurrent-modification, a parent not registered yet, ...) and every 5xx leave no idempotency_keys row at all, so an empty table after a refused request is expected, not a bug.

The sweeper is safe to run in several replicas at once. It logs housekeeping sweep with idempotency_keys_deleted and outbox_events_deleted when it removed rows, and housekeeping sweep failed on error. It never crashes the process.

Chart wiring: templates/configmap.yaml renders HTTP_ADDR, MIGRATIONS_PATH, EVENT_PUBLISHER, OUTBOX_RELAY_INTERVAL, OUTBOX_MAX_ATTEMPTS, HOUSEKEEPING_INTERVAL, IDEMPOTENCY_KEY_TTL, OUTBOX_RETENTION, SITE_CAPABILITY_HEARTBEAT_INTERVAL and KAFKA_BROKERS (from kafka.brokers, mandatory) from config.*, and the api Deployment mounts it with envFrom (gap fix D14, 2026-10-12). Changing config.outboxRelayInterval, config.outboxMaxAttempts, config.siteCapabilityHeartbeatInterval or the housekeeping values in values.yaml takes effect on the next rollout (the checksum/config annotation rolls the pods). Explicit env/extraEnv entries win over the ConfigMap for the same key. The projector, reports and MCP Deployments do not mount it: they set their own variables explicitly. charts/facility-layout/tests/render_test.sh (CI job chart-tests) fails if the mount disappears.

Analytics reports API (facility-reports)​

These routes are served by cmd/facility-reports (internal/adapters/inbound/http/reports_handler.go) and specified in apis/openapi-reports.yaml, a separate spec from the OLTP apis/openapi.yaml (gap fix D18). Errors are RFC 7807: 400 invalid-report-query, 500 report-store-error.

RouteQuery parameters200 response
GET /reports/catalog-growthfrom, to (RFC3339, required); scope (optional, exact match on the row scope: a site code for site and zone events, a zone id for aisle and slot events; omitted or empty means no filter). Catalog-wide definitions (location types, placement rules, imports) are stored under the empty scope, so they only show up unfiltered. from is inclusive and to is exclusive. granularity (optional, only day){"rows":[{"scope","dayBucket","sitesRegistered","zonesRegistered","aislesRegistered","locationTypesRegistered","placementRulesDefined","slotsRegistered","slotsDecommissioned","bulkImports","importRowsSubmitted","importRowsImported","importRowsRejected"}]}
GET /reports/catalog-growth/freshnessnone{"lagSeconds": <float>}
GET /healthz, GET /readyznone{"status":"ok"} / {"status":"ready"}

A missing or malformed parameter returns RFC 7807 400 with problem type invalid-report-query. A store error returns 500 with report-store-error. See Catalog growth report for what the numbers mean.

Scaling​

  • HPA (templates/hpa.yaml, autoscaling/v2, CPU target 70%). It is off by default. When it is on, the Deployment's replicas is omitted. Limits: api 1–4, projector 1–2, reports 1–3, frontend 1–3.
  • mcp has no HPA by design. The go-sdk Streamable HTTP handler keeps in-memory sessions keyed by Mcp-Session-Id, and the Service has no session affinity, so keep it at 1 replica (ADR-0022).
  • Connection budget. OLTP pool MaxConns is 10 per process with statement_timeout 5s (internal/adapters/outbound/postgres/pool.go), so 4 api replicas use 40 connections against PgBouncer, plus 10 for mcp. Analytics pools: projector 5, reports 5 (read-only).
  • Projector replicas share group facility-analytics, and writes are idempotent per event id, so N > 1 is safe. Throughput is still bounded by the topic's partition count.

Routine procedures​

TaskHow
Deploy a new versionBump the image tag in warehouse-infra. Pods apply pending migrations on boot. Watch for succeeded after retry and telemetry configured log lines, then for http server listening.
Check the outbox backlogSELECT count(*), min(created_at), max(attempts) FROM outbox_events WHERE published_at IS NULL; A growing count means the relay cannot reach Kafka: read last_error.
Re-publish an eventClear the row's publish mark: UPDATE outbox_events SET published_at = NULL WHERE id = <id>; The relay sends it again with the same CloudEvents id, which consumers treat as a duplicate. Rows older than OUTBOX_RETENTION have already been swept.
Replay the analytics read modelStop the projector, truncate catalog_growth_rollup, analytics_processed_events and analytics_consumed_events, reset group facility-analytics to earliest (kafka-consumer-groups --reset-offsets --to-earliest --group facility-analytics --topic warehouse.facility.analytics --execute), then start it again. The replay only covers messages still within the topic's retention.
Replay a dead-lettered messageInspect it on warehouse.facility.analytics.dlq (the body is byte-identical to the original; the headers say why it failed), fix the cause, then produce the same value and key back onto warehouse.facility.analytics. Idempotency on the CloudEvents id makes a double replay harmless.
Rotate database credentialsUpdate the Secret keys DATABASE_URL and MIGRATIONS_DATABASE_URL (or the analytics Secret's ANALYTICS_DATABASE_URL and ANALYTICS_READER_DATABASE_URL), then kubectl rollout restart the affected Deployments. DSNs are only read at boot.
Purge idempotency keys right awayRestart the api pod: the sweeper runs once at start. You can also run the sweeper's DELETE by hand.
Enable a site for inter-warehouse transfersPUT /sites/{siteCode}/transfer-capability with {"transferOriginEnabled": true, "transferDestinationEnabled": true} (either flag may be false). The response's capabilityRevision is the revision published in SiteCapabilityChanged; network-inventory-planning applies it once the outbox relay has sent it (ADR-0035). A repeat publishes nothing (the periodic heartbeat, ADR-0041, keeps the fact fresh for consumers); a 409 concurrent-modification means another change won the race: re-read and PUT again. Existing sites start capable of nothing at revision 0.
Classify a site (set its network role)PUT /sites/{siteCode}/role with {"siteRole": "NON_SORTABLE_FC"} (one of the 15 roles of GET /site-roles/transfer-defaults; UNSPECIFIED is rejected). Publishes SiteRoleChanged; a repeat publishes nothing. It does NOT change the transfer capability (ADR-0037).
Apply the per-role transfer defaultsRead GET /site-roles/transfer-defaults (the one source of truth) and GET /sites; for every Active site whose siteRole has a row, PUT /sites/{siteCode}/transfer-capability with that row's flags. Sites still UNSPECIFIED have no default: classify them first. warehouse-infra's seed script does exactly this.
Check the role backfill after migration 0009SELECT site_role, count(*) FROM sites GROUP BY site_role ORDER BY 1; Sites left UNSPECIFIED had a name outside the 15 role phrases (ADR-0037 lists them); classify them with PUT /sites/{siteCode}/role.