Skip to main content

Runbook

Deployment​

The service ships as one Helm chart, charts/network-inventory-planning (chart name network-inventory-planning), and one image, ghcr.io/iqvo/network-inventory-planning (all four binaries in /app). Edge routing is owned by warehouse-infra: Kong :8000 serves the REST API under /api/network-inventory-planning through the chart's disabled-by-default gatewayApi / ingress values; the Nginx web gateway :80 serves the console remote under /mfes/network-inventory-planning/.

Deployment (component label)CommandEnabled byContainer portServiceProbes
apiimage entrypoint ./network-inventory-planningalways8080 (http)ClusterIP 80 → 8080startup, liveness and readiness all GET /healthz (startup: every 2s, 30 failures = 60s for migrations)
mcp/app/mcpmcp.enabled8090ClusterIP 8090GET /healthz
analytics-projector/app/nip-projectoranalytics.enabled8091 (admin)nonestartup + liveness GET /healthz, readiness GET /readyz
analytics-reports/app/nip-reportsanalytics.enabled8092ClusterIP 80 → 8092GET /healthz
frontend (nip_mfe)nginxfrontend.enabled8080ClusterIP 80 → 8080GET /healthz

What the probes actually prove​

  • api: there is no /readyz. GET /healthz answers 204 as soon as the HTTP server listens, and the server only starts listening after the migrations applied and the pool pinged (wire runs before ListenAndServe). Kafka is not checked: consumers and the relay start in goroutines, and a broker outage shows up in logs and consumer lag, not in the probes.
  • mcp: GET /healthz is a static {"status":"ok"}; like the API it only listens after migrations and the ping (when DATABASE_URL is set).
  • analytics-projector: /healthz never flips; /readyz answers {"status":"ready"} and flips to 503 {"status":"not_ready"} as the first step of graceful shutdown. The analytical migrations and the database ping run before the admin server starts, each retried by internal/bootretry (5 attempts, 1s doubling: 1+2+4+8 = 15s of backoff) to survive the Istio first-dial reset.
  • analytics-reports: GET /healthz is static; the database ping before listening is retried the same way.

terminationGracePeriodSeconds is 30; every binary drains its HTTP server for up to 10s on SIGTERM.

Migrations​

DatabaseDirectoryRun byWhen
OLTPinternal/adapters/outbound/postgres/migrations (/app/migrations in the image)network-inventory-planning and mcpAt every start, before the server listens, through golang-migrate. A failure refuses the boot.
Analyticalanalytics/migrationsnip-projector onlyAt every start, under boot retry.

The OLTP migrations are 0001 to 0009: 0001 planning read models (processed_events, site_capability, site_sku_demand, published_capacity_plan), 0002 transfer saga and outbox (inter_warehouse_transfer, transfer_audit, outbox_events), 0003 picked_quantity and stow_allocations plus named CHECKs, 0004 rebalance_runs, 0005 rebalance catalogue (rebalance_policies, transfer_lanes), 0006 pack_levels, 0007 case-rounding columns on the transfer, 0008 idempotency_keys and 0009 the RELEASING state. The analytical database has one migration, 0001_saga_facts. idempotency_keys gets one row per POST and nothing in the repository prunes it (retention is at least 24 hours, the sweep is future work per ADR 0021), so watch its size; the created_at index exists for that sweep. The columns are in Entity-relationship.

MIGRATIONS_DATABASE_URL (secret key database.migrationsExistingSecretKey, optional) gives the migration step a direct connection when DATABASE_URL goes through PgBouncer (ADR 0006). There is no separate migration Job: a release that ships a migration applies it when the first new pod starts; golang-migrate's advisory lock serialises the API and MCP pods.

Kafka​

One broker serves the whole platform (in-cluster; localhost:9092 from the host). Every message is a CloudEvents 1.0 event in structured mode.

Produced​

TopicTypes (com.warehouse.wes.network-inventory-planning. + …)KeyProducer
warehouse.network-inventory-planning.eventstransfer.TransferPlanApproved, transfer.TransferAllocationRequested, workdemand.WorkDemandReleasedtransfer id, transfer_line_id, demand_idoutbox relay in the API
warehouse.network-inventory-planning.analyticssaga.TransferStateAdvanced, saga.TransferStuckDetected, saga.RebalanceRunCompletedtransfer id / run idoutbox relay in the API
warehouse.network-inventory-planning.analytics.dlqraw poison messages from the analytics topicoriginal keynip-projector
warehouse.inventory.events.dlqraw poison replies/facts consumed by transfer-reply-consumer (header x-dlq-consumer: transfer-reply-consumer)original keyAPI (ADR 0013)
warehouse.fulfillment.events.dlqraw poison facts consumed by transfer-fact-consumer (header x-dlq-consumer: transfer-fact-consumer)original keyAPI (ADR 0013)

The relay writer sets AllowAutoTopicCreation (the relay is the first writer of both own topics), RequiredAcks: all and BatchSize: 1. The DLQ writers also auto-create their topic; it only exists after the first poison message. The two consumed-topic DLQs follow the fleet <topic>.dlq convention, so a sibling consumer of the same topic may write there too: filter on x-dlq-consumer.

Consumed​

Consumer (processed_events.consumer)TopicTypesGroup id variableBinary
site-capability-consumerwarehouse.facility.eventscom.warehouse.wms.facility-layout.site.SiteCapabilityChangedSITE_CAPABILITY_CONSUMER_GROUPAPI
site-sku-demand-consumerwarehouse.order-management.eventscom.warehouse.wes.order-management.siteskudemand.SiteSkuDemandChangedSITE_SKU_DEMAND_CONSUMER_GROUPAPI
capacity-plan-consumerwarehouse.warehouse-planning.eventscom.warehouse.wes.warehouse-planning.capacityplan.CapacityPlanPublishedCAPACITY_PLAN_CONSUMER_GROUPAPI
transfer-reply-consumerwarehouse.inventory.eventscom.warehouse.wms.inventory-storage.reservation.TransferStockAllocated, ...reservation.TransferStockAllocationRejected, ...stock.TransferReceiptStaged, ...stock.TransferStockStowedTRANSFER_REPLY_CONSUMER_GROUPAPI
transfer-fact-consumerwarehouse.fulfillment.eventscom.warehouse.wes.fulfillment-execution.transfer.TransferPicked, ...TransferDispatched, ...TransferArrivedTRANSFER_FACT_CONSUMER_GROUPAPI
analytics consumerwarehouse.network-inventory-planning.analyticsthe three saga.* typesANALYTICS_CONSUMER_GROUP (default network-inventory-planning-analytics)nip-projector

The five API group ids have no default and are empty in values.yaml: each is the off switch of its consumer and must be filled per environment. Other types on a consumed topic are ignored.

Delivery semantics​

  • API consumers (internal/adapters/inbound/kafka/kafka.go): at-least-once with an atomic effect. The processed_events claim and the side effect commit in one transaction; the offset is committed only after that. A benign deterministic problem (not a CloudEvent, unknown type, unknown transfer, illegal transition such as a replay or an out-of-order fact, a site-capability or demand domain validation failure) is logged at WARN and committed past. A transfer reply or fact that can never apply — a malformed payload, or one the aggregate refuses (transfer.ErrReplyRefused: line-id mismatch, unknown rejection reason, any other allocation-reply mismatch; transfer.ErrFactRefused: impossible quantity, foreign line, wrong site/SKU) — is written raw to <topic>.dlq with the headers x-dlq-source-topic, x-dlq-consumer, x-dlq-error, x-dlq-failed-at inside the claim's transaction and committed past (ADR 0013); a failed DLQ write rolls the claim back and retries. A transient error retries the same message forever with backoff 200ms → 5s, logging at ERROR, and blocks its partition.
  • Analytics consumer: non-CloudEvents messages are skipped (one WARN per minute with a suppressed count); unknown types are skipped at INFO; a known type with an unusable payload, or one the store deterministically rejects, is written to warehouse.network-inventory-planning.analytics.dlq with the headers x-dlq-source-topic, x-dlq-error, x-dlq-failed-at and committed past. A database outage is retried, never dead-lettered. A failed DLQ write is retried as transient.

Outbox relay​

postgres.OutboxRelay (internal/adapters/outbound/postgres/outbox.go) runs in the API process when KAFKA_BROKERS and OUTBOX_RELAY_ENABLED are set:

  • every 1s it claims up to 100 unpublished rows ORDER BY id with FOR UPDATE SKIP LOCKED and sends them one at a time;
  • a sent row gets published_at = now();
  • a failed send increments attempts, stores last_error, commits, and ends the pass, so no later row overtakes it; the next tick retries it (WARN outbox relay: send failed, stopping this pass at the failed row);
  • once a row has failed OUTBOX_MAX_ATTEMPTS sends (default 20, chart config.outboxMaxAttempts, 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 (ADR 0016). Later rows, including rows with the same key, now overtake it. The row is not deleted: it stays in outbox_events with attempts and last_error.

An outbox row hit the attempt cap​

-- excluded rows (use your OUTBOX_MAX_ATTEMPTS value)
SELECT id, topic, event_type, key, attempts, last_error
FROM outbox_events
WHERE published_at IS NULL AND attempts >= 20
ORDER BY id;

Fix the cause in last_error (topic, broker, message size), then re-arm the row; the next relay pass claims it again and sends the stored bytes with the same CloudEvents id:

UPDATE outbox_events SET attempts = 0 WHERE id = 123;

A re-armed row reaches consumers after later rows with the same key; consumers deduplicate on the CloudEvents id and must tolerate that late delivery.

Without the relay, approvals and fact applications still commit and their rows wait in outbox_events.

Tickers (housekeeping)​

Both run inside every API replica, only when an outbox publisher exists.

TickerVariableDefaultWhat a tick does
Saga health checkNIP_HEALTH_CHECK_INTERVAL, NIP_STUCK_THRESHOLDSevery 5m; ALLOCATING 1h, RELEASING 1h, PICKED 24h, IN_TRANSIT 72h, others 24hReads up to 500 non-terminal transfers and writes one TransferStuckDetected outbox row per transfer older than its state's threshold. It never changes a transfer.
Scheduled rebalanceNIP_REBALANCE_SCHEDULEoffBuilds the fail-closed snapshot, runs the planner, inserts a rebalance_runs row (COMPLETED or FAILED with fail_closed_reason) and writes a RebalanceRunCompleted row. It never approves anything. It plans from the Rebalance Policy and Transfer Lane catalogues (ADR 0015): with both empty every completed run records proposal_count = 0; fill them with PUT /v1/rebalance-policies and PUT /v1/transfer-lanes. An unreadable catalogue is a FAILED run (load rebalance catalogue: …).

There is no sweeper: processed_events, outbox_events (published rows), transfer_audit and rebalance_runs grow without bound. Pruning them is a manual operation.

Analytics reports​

nip-reports serves these routes (all GET, JSON, also in the API reference):

RouteQueryResponse
/reports/transfer-funnelfrom, to (RFC 3339, optional){from, to, days:[{day, state, transfers}]}
/reports/state-dwellfrom, to{from, to, days:[{day, state, transitions, p50_age_seconds, p95_age_seconds}]}
/reports/stuck-transfersfrom, to, limit (1–100, default 20){from, to, days:[{day, state, detections, transfers}], latest:[{transfer_id, state, age_seconds, threshold_seconds, detected_at}]}
/reports/rebalance-runsfrom, to{from, to, days:[{day, runs, proposals, rejected, rejection_rate, stale_facts}]}
/reports/freshnessnone{as_of, lag_seconds} (both null until the first event is applied)
/healthznone{"status":"ok"}

Ranges are half-open [from, to), default to the 30 days ending now and may not exceed 366 days; a bad range is a 400 invalid-report-range, a bad limit a 400 invalid-report-limit, a database failure a 500 report-store-error (cause not echoed). Days are UTC calendar dates.

Scaling​

  • api: autoscaling (HPA, 1–3 replicas, 70% CPU) is off by default. Extra replicas share each consumer group's partitions safely (dedupe by processed_events). Two things multiply with replicas: both tickers (each replica runs its own health check and rebalance, producing duplicate occurrences) and outbox relays (SKIP LOCKED gives each relay a disjoint batch, so strict id order across all rows only holds with one relay).
  • pgxpool: OLTP MaxConns 10 per process; analytical writer and reader 5 each. Budget replicas × 10 (API) + replicas × 10 (MCP) against Postgres.
  • analytics-projector: HPA capped at 2; writes are idempotent on the CloudEvents id. analytics-reports: stateless, HPA up to 3.

Routine procedures​

TaskProcedure
Re-publish an eventUPDATE outbox_events SET published_at = NULL, attempts = 0, last_error = NULL WHERE id = <id>; The relay resends the stored bytes with the same CloudEvents id, so consumers deduplicate it.
Unblock a relay stuck on one rowSELECT id, topic, event_type, attempts, last_error FROM outbox_events WHERE published_at IS NULL ORDER BY id LIMIT 5; Fix the cause (topic, broker, ACLs). Every row behind the failing one waits until it succeeds or reaches OUTBOX_MAX_ATTEMPTS (then see An outbox row hit the attempt cap).
Replay a read-model topicReset the group's offsets with the Kafka tools while the API is scaled to 0. Events already in processed_events for that consumer are skipped; delete those rows first if they must be re-applied.
Rebuild the analytics modelThe projection can be dropped and rebuilt from the topic: point ANALYTICS_CONSUMER_GROUP at a new group id (it starts from the earliest offset) on an emptied analytical database, or reset the existing group's offsets.
Drain the analytics DLQRead warehouse.network-inventory-planning.analytics.dlq, inspect x-dlq-error, fix the producer or projection, and re-produce the raw value to the analytics topic.
Drain a transfer DLQRead warehouse.inventory.events.dlq / warehouse.fulfillment.events.dlq, keep the rows whose x-dlq-consumer is transfer-reply-consumer / transfer-fact-consumer, inspect x-dlq-error. A refused reply means the producer and NIP disagree about the transfer (line, origin, SKU, quantity): fix the producer. Re-producing the raw value only helps once the cause is fixed, and needs the processed_events row for that CloudEvents id deleted first (the claim committed with the dead letter).
Rotate database credentialsUpdate the Secret (database.existingSecret / analytics.database.existingSecret) and restart the Deployments: DSNs are read only at start.
Enable approval in a new environmentSet kafka.enabled, the five group ids, config.transferPickPathId and config.transferDispatchPathId; keep config.outboxRelayEnabled: "true".
Investigate a stuck transferGET /v1/transfers/{id} (audit trail), the MCP tool find_stuck_transfers, or GET /reports/stuck-transfers. See Troubleshooting.