Node Performance runbook
Bounded context Node Performance (Supporting, partner tier) measures every node of the retail
network against what it declared and what was asked of it (acknowledgement latency, rejections,
on-time handover against requiredShipBy, promise-kept rate and inventory feed freshness) over
rolling 7-day and 30-day windows, and grades the node (A to D from 50 observations,
PROVISIONAL below). It consumes six sibling event topics, keeps two scorecards per node,
publishes NodeScorecardUpdated, NodeTierEligibilityChanged and NodeThresholdBreached through a transactional outbox and
serves two read-only REST routes. This repository is a domain-driven design study; it is not
associated with any company (README.md disclaimer). Every variable is in
Configuration; the symptom-driven view is
Troubleshooting.
Runtime shape
Three binaries, one chart (charts/node-performance/), three independent Deployments:
| Binary | Role | Port | Chart switch | Kong route (kind cluster) |
|---|---|---|---|---|
cmd/api | REST, six consumers, recompute scheduler, outbox relay (ONE process) | 8080 (Service 80) | always on | /api/node-performance (prefix stripped) |
cmd/mcp | read-only MCP, Streamable HTTP on /mcp and / | 8090 | mcp.enabled (off by default) | /api/mcp/node-performance (rewritten to /mcp) |
cmd/a2a | read-only A2A agent, JSON-RPC on / and /a2a, Agent Card at /.well-known/agent-card.json | 8093 | a2a.enabled (off by default) | /api/a2a/node-performance (rewritten to /) |
warehouse-infra (helm-values/node-performance.yaml on develop) switches mcp, a2a and the
frontend (the node_performance_mfe console remote) on, with their routes. cmd/mcp and
cmd/a2a read the same Postgres through the same two read use cases; they never start a worker,
never dial Kafka and cannot write.
Inside the api process (cmd/api/run.go, cmd/api/workers.go):
- REST on
HTTP_ADDR(default:8080): chi,GET /scorecards/{nodeId},GET /scorecards?grade=&window=&limit=&cursor=, plus the probes. Reads only, no authentication, no state-changing route (internal/adapters/inbound/http). - Six Kafka consumers (vendor-connectivity, shipping-and-tracking, delivery-promise,
offer-availability, node-topology, seller-inbound), one message at a time, offset committed
only after the intake use case returned (
internal/adapters/inbound/kafka/consumer.go). No sibling REST calls: facts arrive only over Kafka (ADR 0003). - Recompute scheduler (the sweeper): runs
Recomputeonce at boot, then everyRECOMPUTE_INTERVAL(default 1m). Each round loads up to 200 due scorecards, up to 10 rounds per run, recomputes them and appends the events to the outbox in the SAME Postgres transaction (cmd/api/workers.gorunRecompute,internal/application/usecases/recompute.go). A failed round is logged at ERROR and retried at the next tick. - Outbox relay: always on, polls every
OUTBOX_RELAY_INTERVAL(default 1s), publishes unpublishedoutbox_eventsrows in id order (internal/adapters/outbound/outbox,internal/adapters/outbound/kafka). - Any worker that returns on its own makes the process run the shutdown sequence and exit
non-zero, so the orchestrator restarts it (
worker stoppedin the log). - Graceful shutdown (SIGINT/SIGTERM):
/readyzflips to 503, waitSHUTDOWN_DRAIN_DELAY(5s), drain HTTP (10s), stop consumers and scheduler (10s), stop the relay LAST (10s), close the pool: 35s of bounds, chartterminationGracePeriodSeconds: 40(Runtime).
Dependencies
- Postgres:
DATABASE_URLis the service's pool (through PgBouncer on the cluster);MIGRATIONS_DATABASE_URLis a direct DSN for the boot migrations, because golang-migrate holds a session advisory lock that breaks behind a transaction-pooling proxy (optional key; the binary falls back toDATABASE_URL). Both DSNs reach the pod from the Secretnode-performance-dbviasecretKeyRef. - Kafka:
KAFKA_BROKERS(one broker platform-wide), used by the consumers, the relay and the/readyzbroker check. Topics are auto-created by the first writer;/readyznever asks for topics. - Boot is resilient to a slow start: migrations and the Postgres ping retry 5 times (1+2+4+8s
backoff,
internal/bootretry); consumers and the relay dial lazily, so a broker that is down at boot does not blocklisten. A consumer is less patient than the relay, though: a refused connection is fatal to its worker (only timeouts, resets and EOFs are retried, up to 10 consecutive fetches,internal/adapters/inbound/kafka/kafka.go). In a real run against a closed port the consumers loggedworker stopped ... failed to dialabout 10 s after boot and the process exited non-zero, to be restarted by the orchestrator. See Troubleshooting.
Migrations
Embedded in the binary (internal/adapters/outbound/postgres/migrations/, golang-migrate) and run
at every start of cmd/api, cmd/mcp and cmd/a2a; the advisory lock makes concurrent starts
safe. There is no separate migration job.
| Migration | Creates |
|---|---|
0001_node_performance_schema | scorecards, scorecard_observations, purchase_order_facts |
0002_outbox_inbox_and_idempotency | outbox_events, processed_events (the inbox), idempotency_keys (no route uses it) |
0003_inbound_read_models | inbound_shipments, inbound_receipts (ADR 0009) |
Check the state with SELECT version, dirty FROM schema_migrations;. A dirty = true row means a
migration died half-way: fix the cause, then migrate force the version by hand; the service
refuses to boot on a dirty database.
Kafka topics and consumer groups
| Direction | Topic | Group variable | Platform group id (warehouse-infra) |
|---|---|---|---|
| consumed | retailnetwork.vendor-connectivity.events | VENDOR_CONNECTIVITY_CONSUMER_GROUP | node-performance-vendor-connectivity |
| consumed | retailnetwork.shipping-and-tracking.events | SHIPPING_AND_TRACKING_CONSUMER_GROUP | node-performance-shipping-and-tracking |
| consumed | retailnetwork.delivery-promise.events | DELIVERY_PROMISE_CONSUMER_GROUP | node-performance-delivery-promise |
| consumed | retailnetwork.offer-availability.events | OFFER_AVAILABILITY_CONSUMER_GROUP | node-performance-offer-availability |
| consumed | retailnetwork.node-topology.events | NODE_TOPOLOGY_CONSUMER_GROUP | node-performance-node-topology |
| consumed | retailnetwork.seller-inbound.events | SELLER_INBOUND_CONSUMER_GROUP | node-performance-seller-inbound |
| published | retailnetwork.node-performance.events | none | NodeScorecardUpdated and NodeTierEligibilityChanged |
| published | retailnetwork.node-performance.analytics | none | NodeThresholdBreached only |
| dead letters | <consumed topic>.dlq | none | written by the consumers |
Group ids are fixed and stable (never the pod name): a rescheduled pod resumes from its committed
offsets, while a brand-new group id re-reads its topic from the first offset. Never change a group
id on a running deployment unless a full replay is wanted; replays are safe because every message is
deduplicated on the CloudEvents id in processed_events.
Health
GET /healthz: liveness, 200{"status":"ok"}while the process serves, even while draining or while a dependency is down (internal/adapters/inbound/http/readiness.go).cmd/mcpandcmd/a2aserve only this probe.GET /readyz(cmd/apionly): 200{"status":"ready"}only when the drain gate is open, Postgres answers a ping AND a Kafka broker answers a metadata request with an empty, non-nil topic list (fresh connection per check, verdicts cached 3s, round bounded 2s). Draining: 503{"status":"not_ready"}. A dependency down: 503application/problem+jsonof typedependency-unavailablenaming postgres or kafka (internal/adapters/inbound/http/problems.go).- Chart probes: startup and liveness on
/healthz, readiness on/readyz(charts/node-performance/values.yaml). - With Kafka down both writers keep working: effects and outbox rows commit in one Postgres
transaction and
outbox_events.published_at IS NULLrows queue until the broker returns (ADR 0005, asserted bycmd/api/e2e_integration_test.go). With Postgres down nothing persists: REST reads fail,/readyzflips, consumers cannot claimprocessed_events, recompute rounds log ERROR and retry.
Outbox relay
-
Events are written in the same transaction as the aggregates and published later; delivery is at-least-once with a stable CloudEvents
id; consumers deduplicate. -
A row that failed
OUTBOX_MAX_ATTEMPTStimes (20) is skipped (logged once at ERROR with id, topic, type and key) and stays in the table withattemptsandlast_error; later events of the same scorecard can overtake it. Inspect and re-arm:SELECT id, event_id, topic, event_type, attempts, last_error, created_atFROM outbox_events WHERE published_at IS NULL AND attempts >= 20 ORDER BY id;UPDATE outbox_events SET attempts = 0 WHERE id = <id>;Table defined in
internal/adapters/outbound/postgres/migrations/0002_outbox_inbox_and_idempotency.up.sql. -
Queue depth:
SELECT count(*) FROM outbox_events WHERE published_at IS NULL;
Dead-letter queues
A transient failure (database down, purchase-order facts not arrived yet) is retried up to 5
attempts (maxHandlerAttempts, internal/adapters/inbound/kafka/deadletter.go) with backoff 200ms
doubling to 5s, then published to <topic>.dlq; a payload that can never be applied is dead-lettered
at once. The DLQ message keeps the original key, value and headers and adds x-dlq-source-topic,
x-dlq-source-partition, x-dlq-source-offset, x-dlq-error and x-dlq-failed-at. A message that
is not a CloudEvents 1.0 event, or of an unhandled type, is skipped, not dead-lettered. Nothing in
this repository reads a DLQ back: read x-dlq-error, fix the producer or dependency, and
republish the payload to the source topic by hand if it is still wanted.
Deployment (Helm)
charts/node-performance/ deploys the api by default; mcp, a2a and frontend are opt-in
(values.yaml documents every key; each config.* value maps 1:1 to one variable, and the chart
ConfigMap, mounted with envFrom with a checksum/config pod annotation, carries every one of them
except the two DSNs).
- Required, refused at render with the value named:
database.urlordatabase.existingSecret(DATABASE_URLfrom asecretKeyRef;MIGRATIONS_DATABASE_URLfromdatabase.migrationsExistingSecretKeywithoptional: true),kafka.brokers, and the sixconfig.*ConsumerGroupvalues (vendorConnectivity,shippingAndTracking,deliveryPromise,offerAvailability,nodeTopology,sellerInbound). - Observability (ADR 0010):
otel.enabled,otel.endpoint,otel.serviceNamerenderOTEL_EXPORTER_OTLP_ENDPOINTandOTEL_SERVICE_NAME(<name>-mcpfor mcp,<name>-a2afor a2a);SERVICE_VERSIONisimage.tagor the appVersion,ENVIRONMENTisenvironment.extraEnvmay not set any of the four. - Also refused: a group id that is an env expansion (
$(POD_NAME)), any*_MODEor chart-managed variable inextraEnv, aconfig.httpAddrport that is notservice.targetPort, and aterminationGracePeriodSecondsbelowconfig.shutdownDrainDelay+ 35 s (40 s with the default). a2a.agentUrlempty rendershttp://<release>-a2a.<namespace>.svc.cluster.local:<service.port>/asA2A_AGENT_URL.- Pod: uid 1000,
runAsNonRoot, read-only root filesystem, no privilege escalation, all capabilities dropped, seccompRuntimeDefault. - HPA, Ingress and Gateway API HTTPRoute are off by default. More than one
apireplica is safe by design (the relay claims withFOR UPDATE SKIP LOCKED, consumers share one group per topic) but has not been load-tested. - Tests:
bash charts/node-performance/tests/render_test.shandpython3 charts/node-performance/tests/test_service_selectors.py, both run by thechart-testsCI job;helm-lint(pull requests) runsct lintand the selector test. Thereleasejob packagesnode-performance-<version>.tgz; the image isghcr.io/iqvo/node-performance(Before first release).
Alerts and dashboards
Managed in warehouse-infra (develop), not in this repository:
- Grafana dashboard uid
warehouse-node-performance(terraform/dashboards/contexts/node-performance.json): Kong request rate, 5xx ratio and p95 latency for the context's routes; service HTTP RED byservice_name=~"node-performance.*"; the business counternodeperformance_scorecards_recomputed_totalbyoutcome; Go runtime; Loki panels on{app="node-performance"}. - Alert group
warehouse-node-performance(terraform/alerting/warehouse-alert-rules.json):WarehouseKong5xxRatioHigh(more than 5% 5xx on a Kong route for 5m, warning) andWarehousePodRestarting(2 or more restarts of anode-performance-.+pod in 15m, warning). - Alert group
warehouse-node-performance-slo:WarehouseApiAvailabilityBurnFastandWarehouseApiLatencyBurnFast(critical, 2m),WarehouseApiAvailabilityBurnSlowandWarehouseApiLatencyBurnSlow(warning, 15m) over the Kong routes (latency objective: upstream under 400 ms). - There is no alert on the recompute counter, the outbox backlog or consumer lag. Watch
outcome="failed"and the unpublished-outbox query above by hand; a flatrecomputedrate while nodes keep reporting means grading has stalled. See Observability.
Operational actions
- Restart:
kubectl -n warehouse-systems rollout restart deploy/node-performance(the Deployment name is the chart fullname<release>-node-performance;-mcpand-a2afor the others). - Logs: Grafana Loki,
app=node-performance; the binaries emit JSON logs on stdout. Worker lifecycle lines to grep:worker running,worker stopped,recompute round,consumer configured,outbox relay configured. - Rollback: redeploy the previous
image.tagchart value (migrations only add tables; there is no down-migration step in the deploy path). - Scale: see the Helm section; the HPA is off by default.
- Force a recompute: restart the
api(the scheduler runs once at boot). - Replay a consumed topic: give the consumer a new group id in the chart (a new group starts at the
first offset); all effects are idempotent on the CloudEvents
id.