Skip to main content

Runtime: configuration, probes, shutdown and the outbox

cmd/api is the main binary (cmd/mcp and cmd/a2a are read-only siblings, ADR 0006 and 0009, with no Kafka, relay or loops). It runs on real PostgreSQL and real Kafka; there is no alternative runtime and no log sink.

Environment​

VariableDefaultMeaning
DATABASE_URLrequiredPostgres DSN of the service's pool. A boot error names it when unset.
MIGRATIONS_DATABASE_URLDATABASE_URLDirect DSN for the boot migrations (golang-migrate holds a session advisory lock, which breaks behind a transaction-pooling proxy).
KAFKA_BROKERSrequiredComma-separated host:port list (relay, consumers and /readyz). A boot error names it when unset or blank.
NODE_CONSUMER_GROUP, LISTING_CONSUMER_GROUP, SOURCING_CONSUMER_GROUP, INBOUND_CONSUMER_GROUP, PACKAGING_CONSUMER_GROUP, CUSTOMER_RETURNS_CONSUMER_GROUPrequiredStable consumer group ids of the node-topology, offer-availability (listings), order-sourcing, seller-inbound (shipments), offer-availability (packaging) and customer-returns (return advices) consumers. A boot error names the missing one.
NODE_TOPOLOGY_URL, OFFER_AVAILABILITY_URL, SHIPPING_AND_TRACKING_URL, NODE_PERFORMANCE_URLrequiredBase URLs of the four synchronous in-org calls (ADR 0002 A24).
EVENT_PUBLISHERkafkaOnly kafka is accepted; any other value is a boot error.
HTTP_ADDR:8080Listen address.
A2A_ADDR:8093Listen address of cmd/a2a (ADR 0009).
A2A_AGENT_URLrequired (cmd/a2a only)Absolute http(s) URL the Agent Card advertises for the JSON-RPC endpoint; refused at boot otherwise. The chart defaults it to the in-cluster Service.
TX_PROCESSING_DELAY0Least time a submission stays PROCESSING (Go duration).
TX_FAILURE_RATE0Share (0..1) of submissions that end FAILURE with ErrSimulatedFailure.
PO_REDELIVERY_RATE0Chance (0..1) that a poll page repeats its first order.
RATE_LIMIT_RPS0Requests a second over /vendor/*; 0 = unlimited. Over the limit: 429 rate-limited.
SUBMISSION_POLL_INTERVAL1sHow often due submissions are processed.
EXPIRY_SWEEP_INTERVAL30sHow often unacknowledged orders past ackBy are expired.
OUTBOX_RELAY_INTERVAL1sPoll interval of the relay (Go duration or seconds).
OUTBOX_MAX_ATTEMPTS20Failures before the relay excludes a row; 0 = unlimited.
SHUTDOWN_DRAIN_DELAY5sWait between flipping /readyz to 503 and closing the listener; 0 disables.
LOG_LEVELinfodebug, info, warn, error.
OTEL_SERVICE_NAMEvendor-connectivity (-mcp for cmd/mcp, -a2a for cmd/a2a)service.name of spans and metrics (ADR 0008).
OTEL_EXPORTER_OTLP_ENDPOINTlocalhost:4317Collector OTLP/gRPC endpoint; export never blocks, a missing Collector only drops telemetry.
SERVICE_VERSION, ENVIRONMENTdev, localservice.version and deployment.environment.name of the telemetry.

Configuration errors are raised before anything is opened or bound.

Boot and stop​

  1. Validate the environment. 2. Run the embedded migrations and ping Postgres, both with backoff. 3. Start the outbox relay, the five consumers and the three loops (submission processor, expiry sweeper, daily retention sweeper). 4. Serve.

On SIGINT/SIGTERM: /readyz flips to 503 not_ready, wait SHUTDOWN_DRAIN_DELAY, drain HTTP (10 s), stop and await the consumers and loops (10 s), then the relay (10 s), close the pool. If a consumer, a loop or the relay returns on its own, the process exits non-zero so the orchestrator restarts it.

Probes​

  • GET /healthz is liveness: 200 {"status":"ok"} while the process serves, even while draining or while a dependency is down.
  • GET /readyz is 200 only if the drain gate is open, Postgres answers a ping and a Kafka broker answers a metadata request. The request names no topics (an empty, non-nil list), so it never creates a topic; a fresh connection is dialled on every check. While draining it answers 503 not_ready; while a dependency is down, 503 application/problem+json of type dependency-unavailable naming it. Verdicts are cached 3 s.

The outbox and the consumers in operation​

  • Events are written in the same transaction as the aggregates and published later, so a write is accepted while Kafka is down; outbox_events.published_at IS NULL rows wait and are published, in id order, when the broker is back. Delivery is at-least-once with a stable CloudEvents id.
  • A row that failed OUTBOX_MAX_ATTEMPTS times is skipped (logged once at ERROR with id, topic, type and key) and stays in the table with attempts and last_error. Fix the cause, then re-arm it: UPDATE outbox_events SET attempts = 0 WHERE id = <id>;.
  • Consumers claim each CloudEvents id in processed_events in the same transaction as their writes. A transient failure is retried, then published to <topic>.dlq; a payload that can never decode goes there at once. A release for a node the view does not know yet is retried (ADR 0002 A4).
  • Idempotency keys older than 24 h are purged by the daily retention sweep (an expired key is also replaced on its next use); processed submissions are purged after 30 days by the same sweep.

Deployment (Helm chart)​

charts/vendor-connectivity/ runs cmd/api as one Deployment (component=api); the relay, the consumers and the loops live in that process. config.* values map 1:1 to the variables above and are rendered both into the chart ConfigMap (envFrom) and into the container env from one helper; tests/render_test.sh fails when cmd/api reads a variable the chart does not render, or the chart renders one the binary does not read.

ValueVariableRule
database.url or database.existingSecret (+ existingSecretKey)DATABASE_URLsecretKeyRef, never in the ConfigMap; render fails when neither is set.
database.migrationsExistingSecretKeyMIGRATIONS_DATABASE_URLsecretKeyRef with optional: true; the binary falls back to DATABASE_URL.
kafka.brokersKAFKA_BROKERSRequired.
config.nodeConsumerGroup, config.listingConsumerGroup, config.sourcingConsumerGroup, config.inboundConsumerGroup, config.packagingConsumerGroup, config.customerReturnsConsumerGroupNODE_/LISTING_/SOURCING_/INBOUND_/PACKAGING_/CUSTOMER_RETURNS_CONSUMER_GROUPRequired, stable and service-prefixed (vendor-connectivity-node, ...), never the pod name.
config.nodeTopologyUrl, offerAvailabilityUrl, shippingAndTrackingUrl, nodePerformanceUrlNODE_TOPOLOGY_URL, OFFER_AVAILABILITY_URL, SHIPPING_AND_TRACKING_URL, NODE_PERFORMANCE_URLRequired, no default.
config.eventPublisherEVENT_PUBLISHEROnly kafka; *_MODE and a non-kafka publisher in extraEnv are refused.
config.txProcessingDelay, txFailureRate, poRedeliveryRate, rateLimitRps, submissionPollInterval, expirySweepInterval, outboxRelayInterval, shutdownDrainDelaythe simulation, loop, relay and drain variablesOptional; not rendered while empty so the binary default applies. shutdownDrainDelay takes whole seconds.
config.outboxMaxAttemptsOUTBOX_MAX_ATTEMPTSDefault 20, 0 = unlimited.
terminationGracePeriodSecondsn/aDefault 40; refused under 40 and under drain delay + 30 s (drain delay 5 s + HTTP 10 s + consumers and loops 10 s + relay 10 s = 35 s).

The pod runs as uid 1000 with a read-only root filesystem, no privilege escalation, all capabilities dropped and the RuntimeDefault seccomp profile; liveness is /healthz, readiness /readyz, plus a startup probe covering the boot retry. The release job packages vendor-connectivity-<version>.tgz and pushes it to oci://ghcr.io/iqvo.