Skip to main content

Integration

One integration topic out (plus a separate analytics topic). Two topics in and up to two synchronous calls to siblings. Postgres and Kafka are mandatory (ADR 0038); only the two REST edges are selected by an env var. The table below lists every edge in cmd/workforce/main.go.

DirectionCounterpartMechanismSelected byDefault
Outwes-work-planning, warehouse-planningKafka warehouse.workforce.events (ShiftPlanCommitted), through the transactional outboxalways (KAFKA_BROKERS required)n/a: there is no log-only publisher
Outown analytics projectorKafka warehouse.workforce.analytics (every domain event), through the outboxalwaysn/a
In (sync)fulfillment-executionGET /capacity/{capability} on every CommitShiftPlan (ADR 0014)INSTALLED_CAPACITY_MODE=http + FULFILLMENT_EXECUTION_BASE_URLbinary: permissive = every commit fails with 503 (REST sync edge, out of scope of ADR 0038); Helm chart: http against http://fulfillment-execution.<release namespace>.svc.cluster.local:80 (gap fix D24)
In (sync)labor-performanceGET /task-types/{taskType}/performance when ProposePathPlan has no caller rate (ADR 0012)LABOR_PERFORMANCE_MODE=http + LABOR_PERFORMANCE_BASE_URL (REST rollback)kafka-cache; permissive is a boot error
In (async)labor-performanceKafka warehouse.labor-performance.events (TaskPerformanceRecorded) into an in-memory cache (ADR 0019, ADR 0020)LABOR_PERFORMANCE_MODE=kafka-cacheon
In (async)process-path-managementKafka warehouse.process-path-management.events (ProcessPathCreated/Updated/Deactivated) into the in-memory process-path cataloguealways (PATH_CATALOGUE_SOURCE unset or kafka)on; file is a boot error
In (async)warehouse-planningKafka warehouse.warehouse-planning.events (LabourPlanCommitted) into the Postgres labour-plan copy labour_requirements (ADR 0043)LABOUR_PLAN_CONSUMER_GROUP (required)always on

The Helm chart defaults the installed-capacity edge to http against fulfillment-execution's in-cluster Service (config.installedCapacityMode, config.fulfillmentExecutionBaseUrl). The warehouse-infra kind cluster also sets INSTALLED_CAPACITY_MODE=http (through extraEnv, which wins over the chart ConfigMap), LABOR_PERFORMANCE_MODE=kafka-cache and PATH_CATALOGUE_SOURCE=kafka, all of which the binary accepts. All of these edges are therefore live there.

What is published​

Topicwarehouse.workforce.events
Eventcom.warehouse.wes.workforce-management.shiftplan.ShiftPlanCommitted — the only type on this topic
Triggera successful CommitShiftPlan
Fan-outone message per PathPlan line
Clientgithub.com/segmentio/kafka-go
Adapterinternal/adapters/outbound/kafka/publisher.go
Consumerswes-work-planning, into its LaborPlanObserved read model, keyed by path_id; warehouse-planning, whose labor-capacity consumer (group warehouse-planning-labor-capacity) registers it as a LABOR capacity constraint

The publisher​

There is one publisher: the transactional outbox relay writes to Kafka (internal/adapters/outbound/kafka). There is no log-only publisher and no direct publish path (ADR 0038).

VariableDefaultMeaning
KAFKA_BROKERSnone, requiredcomma-separated broker list; the service does not boot without it
EVENT_PUBLISHERkafkakept for the chart and warehouse-infra: unset or kafka; log and anything else stop the boot

Local runs need a broker: docker compose up -d --wait starts one.

The fan-out​

A ShiftPlan has multiple PathPlan lines. CommitShiftPlan with three path lines publishes three Kafka messages, one per line, each carrying that single line's planned_heads/planned_rate/planned_hours alongside the plan's site_code (canonical) and building_id (deprecated alias, same value; ADR 0035) and shift_id.

This matches how the consumer keys its read model: LaborPlanObserved is one row per path. Consumers must expect N messages per commit and must not assume a message carries the whole plan.

The domain event carries only the ShiftPlan's identity (the site code — BuildingId in code — and shiftId). The adapter loads the committed plan through the ShiftPlanRepo to expand it. That keeps fan-out an integration concern: the domain has no opinion about message granularity.

The envelope on the wire​

Every message on both topics is a CloudEvents 1.0 event in structured content mode — mandatory, no other envelope, no toggle (ADR 0026). The Kafka message value is the JSON event format and every message carries the header content-type: application/cloudevents+json; charset=UTF-8 next to the W3C trace headers. One line of a committed plan, byte for byte:

{
"specversion": "1.0",
"id": "9f1c2b7e-4c3a-4a1d-9f0b-6c2b8a7d1e33",
"source": "/warehouse/workforce-management",
"type": "com.warehouse.wes.workforce-management.shiftplan.ShiftPlanCommitted",
"subject": "WH1/shift-1",
"datacontenttype": "application/json",
"dataschema": "urn:warehouse:workforce-management:events:ShiftPlanCommitted:v1",
"time": "2026-08-21T22:00:00Z",
"data": {
"site_code": "WH1",
"building_id": "WH1",
"shift_id": "shift-1",
"path_id": "pack",
"planned_heads": 3,
"planned_rate": 30,
"planned_hours": 24
}
}
  • id is a UUID v4 minted once per line message when the event is encoded and persisted with the outbox row, so a relay retry republishes the same id. Every line of a fan-out has its own id.
  • subject is the ShiftPlan aggregate id <siteCode>/<shiftId> (written <buildingId>/<shiftId> before ADR 0035; the value and the Kafka key are unchanged) — the same value as the Kafka key, so every line of a plan lands on one partition.
  • time is the domain occurred-at, RFC 3339 UTC.
  • dataschema is ...:events:... on this topic and ...:analytics:... on warehouse.workforce.analytics; the type is the same on both.

Helpers live in one package, internal/adapters/kafka/cloudevents (New/Decode/ContentTypeHeader, built on the official github.com/cloudevents/sdk-go/v2/event). The full catalog is on the Events page.

Smoke-testing the edge​

This repo's docker-compose.yml runs a Postgres 16 and a single-node Kafka (docker compose up -d --wait, broker on localhost:9092); the fleet's shared kind-cluster broker works too.

export DATABASE_URL="postgres://workforce:workforce@localhost:5432/workforce?sslmode=disable"
export KAFKA_BROKERS=localhost:9092
export LABOUR_PLAN_CONSUMER_GROUP=workforce-management-labour-plans
go run ./cmd/workforce

# two path lines -> expect two messages
curl -X POST localhost:8080/shift-plans \
-d '{"siteCode":"WH1","shiftId":"shift-1","lines":[
{"pathId":"pack","plannedHeads":3,"plannedRate":30,"plannedHours":24,"installedStations":10},
{"pathId":"pick","plannedHeads":2,"plannedRate":25,"plannedHours":16,"installedStations":10}
]}'

# in another terminal (any Kafka CLI pointed at the shared broker, e.g.
# kubectl exec into kafka-controller-0 in the warehouse-systems namespace)
kafka-console-consumer.sh \
--bootstrap-server localhost:9092 \
--topic warehouse.workforce.events \
--from-beginning --max-messages 2

What is deliberately not published​

LaborAssigned, LaborReassigned and PathUnderstaffed never go on the integration topic; they reach only this service's own analytics topic. Since ADR 0034 the analytics PathUnderstaffed carries an optional site_code (additive, still v1): present when the gap was computed for one canonical site, absent when it was computed fleet-wide — consumers must treat absence as "unscoped".

Since ADR 0041 the analytics LaborAssigned and LaborReassigned carry an optional initiated_by object (additive, still v1, event data only, no CloudEvents attribute): {via: "mcp" | "a2a", proposal_id?, approved_by?, agent_id?}. It is present only when the call arrived through the MCP or A2A assign_labor surface, with via set by the adapter, and absent for REST. Consumers must treat absence as "not agent-initiated".

Publishing individual assignment moves would let a downstream context reconstruct a per-associate location feed — exactly the picture the path boundary exists to withhold. If a real downstream need appears, the right answer is a read-model endpoint with a defined shape, not a firehose of moves.

The remaining AssociateShift events stay off the integration topic for the simpler reason that nobody has asked: no sibling consumes roster or break events.

What is consumed​

Three sibling topics. Two only build an in-memory cache that the cmd/workforce process rebuilds from the earliest offset on every start (the catalogue always; the labor-performance cache unless the REST rollback is selected); the third feeds a durable Postgres copy:

  • warehouse.process-path-management.events (internal/adapters/outbound/kafkacatalog). It is the only catalogue source (the boot-time PATH_CATALOGUE_FILE read was removed). Path ids on propose, commit, assign and staffing-gap requests are validated against this cache (ADR 0013).
  • warehouse.labor-performance.events (internal/adapters/outbound/laborperformancecache, LABOR_PERFORMANCE_MODE=kafka-cache, the default). It supplies measured rates to ProposePathPlan and the observed idle share to GetStaffingGap and ProposePathPlan.
  • warehouse.warehouse-planning.events (internal/adapters/inbound/kafka.LabourPlanConsumer, stable group LABOUR_PLAN_CONSUMER_GROUP, ADR 0043). Only com.warehouse.wes.warehouse-planning.labourplan.LabourPlanCommitted is acted on; the CloudEvents id is claimed and the labour_requirements row upserted under the event's version guard in one unit of work; poison goes to warehouse.warehouse-planning.events.dlq. It supplies the heads of a proposal made from the labour plan and the optional requiredHeads on staffing-gap and committed plan lines.

The two cache consumers decode every message with the CloudEvents SDK, dispatch on the full type (com.warehouse.wes.process-path-management.processpath.ProcessPathCreated / Updated / Deactivated and com.warehouse.wes.labor-performance.performance.TaskPerformanceRecorded), and log at WARN and skip anything that is not a valid CloudEvents 1.0 event. The labor-performance cache also dedupes on the CloudEvents id, because its running mean is a sum.

Both consumers use a per-process-unique consumer group (prefix + host + PID + timestamp), so every process replays the full history. Before serving traffic, each one waits up to 60s (WaitReadyTimeout) for the replay to catch up. Neither writes to Postgres, so there is no processed-events table on the OLTP side. The only dedupe table (analytics_processed_events, keyed by the CloudEvents id) belongs to the analytics projector (cmd/workforce-projector), which consumes this service's own warehouse.workforce.analytics topic under the fixed group workforce-analytics.

Synchronous calls to siblings​

  • fulfillment-execution — GET /capacity/{capability} (internal/adapters/outbound/fulfillmentexecution). It is called for every distinct capability the commit's paths require — each line's path is first resolved through the process-path catalogue to its requiredCapabilities (path PICK → capability pick; the path id itself is never sent), and a path's ceiling is the smallest count across its capabilities. It is fail-loud: any failure rejects the whole commit with 503 installed-capacity-unavailable. The default permissive client always fails, so a commit only succeeds when INSTALLED_CAPACITY_MODE=http.
  • labor-performance — GET /task-types/{taskType}/performance (internal/adapters/outbound/laborperformance). It is called only when LABOR_PERFORMANCE_MODE=http and ProposePathPlan gets no positive plannedRate. It is fail-open: on any failure the proposal falls back to the caller rate.

Both clients send no Authorization header (ADR 0018).