Skip to main content

Events

The asynchronous contract lives in apis/asyncapi.yaml (AsyncAPI 2.6.0), linted in CI by Spectral against .spectral.asyncapi.yaml. This page is written from that spec.

The channel​

Topicwarehouse.work-planning.events
ProtocolKafka (localhost:9092 locally; one broker shared by every warehouse-systems service)
Message keythe aggregate id (work unit id for WorkUnit events, path id otherwise) — same as the CloudEvents subject
Default content typeapplication/cloudevents+json
Deliveryat-least-once — consumers must deduplicate

The CloudEvents envelope​

Every message this service produces or consumes — on the integration topic and the analytics topic — is a CloudEvents 1.0 structured-mode event (mandatory fleet standard, ADR-0027). Context attributes and the event-specific data payload travel together in one JSON body; there is no other envelope, no dual mode and no envelope toggle. Events are built and decoded with the official github.com/cloudevents/sdk-go/v2/event package through internal/adapters/kafka/cloudevents. Every produced Kafka message carries the header content-type: application/cloudevents+json; charset=UTF-8 alongside the W3C trace headers.

{
"specversion": "1.0",
"id": "1d7e4b90-3c58-4d22-9a6f-8b1c0e5d7a23",
"source": "/warehouse/wes-work-planning",
"type": "com.warehouse.wes.work-planning.workunit.WorkReleased",
"subject": "wu-10231",
"time": "2026-08-21T22:12:30Z",
"datacontenttype": "application/json",
"dataschema": "urn:warehouse:wes-work-planning:events:WorkReleased:v1",
"data": {
"path_id": "pick-to-tote",
"work_unit_id": "wu-10231",
"cpt": "2026-08-22T02:00:00Z",
"ref": "order-88421-line-3"
}
}
AttributeRule
specversionalways "1.0"
idUUID v4 minted once per domain event and persisted with the outbox row (a redelivery carries the same id); with source, this is the de-duplication key
sourcealways /warehouse/wes-work-planning on this channel
typesee the naming convention below
subjectthe aggregate instance the event is about — a path_id for charge/plan/work-pool events, a work_unit_id for work-unit events
timeRFC 3339, taken from the domain clock, not from publish time
datacontenttypealways application/json
dataschemaurn:warehouse:wes-work-planning:events:<EventName>:v1 on this channel; ...:analytics:<EventName>:v1 on warehouse.wes.analytics

All attributes above are required. The same occurrence carries the same type on both topics; dataschema tells the integration payload from the analytics payload. A breaking payload change requires a new .v2 type and a new dataschema version, published as a new event.

Consumers should ignore type values they do not recognise: new event types may be added to this channel without a major version bump.

The type naming convention​

Shared by every bounded context in the platform:

com.warehouse.<subdomain>.<bounded-context>.<entity>.<EventName>

All segments lowercase except the final PascalCase event name, which matches the past-tense domain event name used in the code. For this service the subdomain is wes and the bounded context is work-planning:

com.warehouse.wes.work-planning.workunit.WorkReleased
com.warehouse.wes.work-planning.workpool.PathThrottled

The <entity> segment names the aggregate that raised the event: workpool (WorkPool and the flow-balancing decisions taken against it) and workunit (WorkUnit). The mapping lives in eventTypeEntity in internal/adapters/outbound/kafka/publisher.go.

Events published​

Topic warehouse.work-planning.events. Eight event types are published; the data shape of each is below.

Event (type suffix after com.warehouse.wes.work-planning.)data fieldsRaised when
workunit.WorkUnitCreatedpath_id, work_unit_id (+ optional reference, line_no, ADR-0041)a work unit is enqueued into a pool
workunit.WorkReleasedpath_id, work_unit_id, cpt, ref (+ optional required_capabilities, fragile, gift_wrap, line_no)the release policy admits the earliest-CPT unit
workunit.WorkUnitCompletedpath_id, work_unit_ida released unit completes
workpool.BacklogThresholdBreachedpath_idbacklog depth crosses the pool's alarm threshold
workpool.RateDeviationDetectedpath_idreserved: declared in the catalogue for a future detection rule (ADR-0020 defers it); not emitted today (decided 2026-10-06)
workpool.PathThrottledpath_idflow balancing decides to throttle upstream release
workpool.LaborReassignmentFlaggedpath_idflow balancing recommends moving headcount
workpool.PathCapacityChangedpath_id, cutoff_at, remaining_units, knownSampleBacklog is called with a cutoffAt query parameter (ADR-0018)

Three types are retired and no longer published (ADR-0049): charge.ChargeForecastReceived, plan.ShiftPlanCommitted and pathplan.PathPlanDriftDetected. The forecast, the labour plan and its drift are warehouse-planning's now (LabourPlanDriftDetected replaces the drift event). The analytics projector still acknowledges the historical messages.

WorkReleased and PathCapacityChanged are the only ones any other service consumes today — fulfillment-execution turns WorkReleased into a Task; order-management and network-fulfillment consume PathCapacityChanged (below). The WorkReleased payload is enriched at the adapter with cpt and ref (read from the WorkUnit repository) so the downstream consumer never has to call back; the domain event itself carries only the two identifiers.

WorkReleased.data also carries three OPTIONAL fields, present only when there is something to say: required_capabilities (array, containing "hazmat" when the released unit's SKU is classified Hazmat by product-master), fragile (bool, true when the SKU is classified Fragile) — see "Product classification propagation" below — and gift_wrap (bool, true when the caller requested gift wrap at enqueue time; read straight off the WorkUnit, ADR-0010).

WorkReleased.data has one more OPTIONAL field, line_no (integer, 1 to 2147483647 — a 32-bit int): the order line the unit was made for, stored on the WorkUnit from the OrderAllocated line that created it and read off it at publish time like ref. It is omitted when unknown — a unit created before ADR-0036, a REST-enqueued unit that gave no lineNo, every transfer unit — and consumers must treat absent as "line unknown". The analytics-topic WorkReleased (warehouse.wes.analytics) carries the same line_no under the same rule. The work-unit id is unchanged ({order_id}-line-{line_no}). An inbound OrderAllocated line whose line_no is above 2147483647 (or non-positive) is not rejected: the unit is still enqueued under the id built from the number as sent, with its stored line left unknown, so WorkReleased omits line_no.

Publication always goes through the transactional outbox to Kafka (KAFKA_BROKERS is mandatory, EVENT_PUBLISHER accepts only kafka; there is no log-only publisher, ADR-0044).

Events consumed​

These belong to other bounded contexts and are documented in their services' own specs; they are listed here for orientation. Every consumer is always on (KAFKA_BROKERS and each consumer group are mandatory, ADR-0044).

Every consumer decodes with cloudevents.Decode and dispatches on the full type string below (never a short name or suffix match); unknown types are ignored. A message that is not a valid CloudEvents 1.0 event — including the retired flat envelope — is published raw to <topic>.dlq and committed past (no retries), never parsed as a legacy shape. A valid event whose handler fails is retried in-process (3 attempts, jittered backoff) and then dead-lettered the same way. time and the dedupe id come from the CloudEvents attributes; the payload from DataAs.

warehouse.workforce.events — from workforce-management​

typedataEffect here
com.warehouse.wes.workforce-management.shiftplan.ShiftPlanCommittedbuilding_id, shift_id, path_id, planned_heads, planned_rate, planned_hourspath_id validated against the process-path catalogue; upserts the LaborPlanObserved projection for path_id. A pure projection: nothing is compared and nothing is published (the drift check moved to warehouse-planning, ADR-0049)

Workforce publishes one message per path line, which is why the projection keys cleanly on path_id. This context holds no shift plan of its own (the plan is warehouse-planning's since ADR-0049); the projection stays as ADR-0006 set it up.

warehouse.inventory.events — from inventory-storage​

typedataEffect here
com.warehouse.wms.inventory-storage.reservation.StockReservedsku, quantity, demand_refDecrements UsableInventoryObserved for that SKU
com.warehouse.wms.inventory-storage.reservation.ReservationRevokedsku, quantity, demand_refIncrements it back

Keyed by SKU, not by path — Inventory reservations are SKU-scoped.

warehouse.fulfillment.events — from fulfillment-execution​

typedataEffect here
com.warehouse.wes.fulfillment-execution.task.TaskCompletedtask_id, station_id, work_unit_id (+ optional task_type)ApplyTaskCompleted passes data.work_unit_id to the existing RecordCompletion use case; an unknown work unit (e.g. a PACK task keyed by order id) is an INFO-logged, processed skip, never DLQ'd

This closes the control loop's feedback edge. ApplyTaskCompleted only adds the atomic processed-event mark around exactly the same code path that POST /work-units/{id}/completions runs.

warehouse.order-management.events — from order-management​

typedataEffect here
com.warehouse.wes.order-management.order.OrderAllocatedorder_id, promise_date, lines[] (line_no, sku, path_id, gift_wrap)ApplyOrderAllocated: every line's path_id is validated against the catalogue first, then one EnqueueWorkUnit per line with id {order_id}-line-{line_no} and CPT = promise_date; an already-enqueued line is a benign no-op (ADR-0031)
com.warehouse.wes.order-management.order.OrderPartiallyAllocatedsame shapesame effect

warehouse.network-inventory-planning.events — from network-inventory-planning​

typedataEffect here
com.warehouse.wes.network-inventory-planning.workdemand.WorkDemandReleaseddemand_id, work_kind (TRANSFER_PICK, TRANSFER_DISPATCH, TRANSFER_ARRIVAL), transfer_ref, path_id, site_id, cpt, sku, quantityApplyWorkDemandReleased: path_id is validated against the catalogue and work_kind against the transfer legs, then one EnqueueWorkUnit with id = demand_id; a different event carrying an already-enqueued demand_id is a benign no-op (ADR-0033)

warehouse.slotting-optimization.events — from slotting-optimization​

typedataEffect here
com.warehouse.wms.slotting-optimization.slotplan.SlotPlanApprovedplan_id, site_id, approved_at, supersedes_plan_id?, moves[] (sku, kind, from_slot?, to_slot?)ApplySlotPlanApproved: one RELOCATE work unit per move on path RELOCATE (id <plan_id>-move-<move_seq>); the site's older plans' unreleased moves are cancelled, and a move into a slot another move of the plan vacates waits for it (ADR-0040). Other types on the topic (SlotPlanGenerated, SlotPlanRejected) are ignored

warehouse.pick-face-replenishment.events — from pick-face-replenishment​

typedataEffect here
com.warehouse.wms.pick-face-replenishment.replenishment.ReplenishmentRequestedrequest_id, site_id, sku, forward_bin, source_bin, quantity, priority (NORMAL, URGENT), requested_atApplyReplenishmentRequested: one REPLENISH work unit per request on path REPLENISH (id replenish-<request_id>), CPT = requested_at plus the priority's horizon; a second event for the same request is a no-op (ADR-0042)
com.warehouse.wms.pick-face-replenishment.replenishment.ReplenishmentCancelledrequest_id, reasonApplyReplenishmentCancelled: cancels the unit and withdraws its pool entry while it is still Pending; released or completed work runs to completion. ReplenishmentCompleted is ignored

warehouse.product-master.events — pack levels (ADR-0045)​

com.warehouse.wms.product-master.product.ProductPackLevelDeclared, ...ProductPackLevelRetired and ...ProductPackLevelMeasured are applied by ObservePackLevel to a version-guarded local copy of the SKU's pack levels, keyed by GTIN, under its own consumer group PACK_VIEW_CONSUMER_GROUP (ADR-0045). They create no work: the copy backs the CASE_PICK check at enqueue time and the pack facts of the charge and travel estimates. Payloads are on the Integration events page.

warehouse.process-path-management.events — from process-path-management​

With PATH_CATALOGUE_SOURCE=kafka, the catalogue cache replays com.warehouse.wes.process-path-management.processpath.ProcessPathCreated, ...ProcessPathUpdated and ...ProcessPathDeactivated. Invalid CloudEvents on this topic are logged at WARN and skipped.

Product classification propagation (local copy of product-master, ADR-0035)​

product-master owns SKU-level classification master data (Hazmat/Fragile/TemperatureSensitive/Oversized/HighValue tags, temperature class, DOT hazard class) and publishes every change as com.warehouse.wms.product-master.product.ProductClassified on warehouse.product-master.events (key and subject = the SKU; data is a full-state replacement carrying the aggregate version). Downstream, fulfillment-execution's Task benefits from knowing hazmat-capability and fragile handling at claim time, without a live per-task callback.

Integration mechanism: a Kafka-fed local copy, read once at release. Until ADR-0035 this was a synchronous HTTP read from inventory-storage's GET /products/{sku}/classification (ADR-0009); classification moved to product-master (its ADR 0001/0003, inventory-storage ADR 0034) and that endpoint is being retired.

typedataEffect here
com.warehouse.wms.product-master.product.ProductClassifiedsku, handling_tags, temperature_class?, dot_hazard_class?, classification_source, versionUpserts product_classification_copy for the SKU only when version is newer than the stored row; other product-master types are ignored
  • PRODUCT_CLASSIFICATION_MODE defaults to kafka; permissive, off and http are rejected at boot (ADR-0044).
  • cmd/wes always runs a dedicated consumer (internal/adapters/inbound/kafka/product_classification_consumer.go) under the stable group PRODUCT_CLASSIFICATION_CONSUMER_GROUP. It claims the CloudEvents id and upserts in one transaction (ObserveProductClassification, ADR-0028); invalid CloudEvents/payloads are WARN-skipped; transient errors retry the same message; the offset is committed after success. cmd/mcp reads the same table read-only.
  • The lookup (internal/adapters/outbound/productclassificationcopy/, port ports.ProductClassificationLookup) returns ProductClassificationView{SKU, HandlingTags, TemperatureClass, Known}: exactly what the HTTP client used to return.
  • ReleaseNextWork's outbound Kafka publisher (internal/adapters/outbound/kafka/publisher.go) reads the released unit's SKU classification once, at publish time, and stamps two OPTIONAL WorkReleased.data fields: required_capabilities (array, appends "hazmat" when the SKU carries the Hazmat tag) and fragile (bool, true when the SKU carries the Fragile tag). Both fields are omitted — not defaulted to an explicit empty array / false — when the SKU is unclassified, not yet in the copy, has no SKU at all, or the copy is unreadable (a read error).
  • Fail-open, not fail-closed. Unlike inventory-storage's own StowStock placement check, a classification problem here must never block or delay releasing work — it can only omit an optional enrichment. The read runs in a savepoint inside the release transaction so a failed read cannot abort it. The copy is eventually consistent: a SKU classified moments before its first release can be released without hints.

Remaining path capacity (ADR-0018)​

GET /paths/{pathId}/telemetry accepts an optional cutoffAt (RFC3339) query parameter. When supplied, SampleBacklog additionally computes the path's current remaining admission capacity from its own WorkPool (max(0, wipLimit - WIP) — clamped, because a pool rehydrated after its limit was lowered can hold more WIP than its limit) and publishes PathCapacityChanged on this topic, correlated against the given CPT cutoff timestamp:

{
"specversion": "1.0",
"id": "5c7d3f92-1b64-4a08-9e73-2f6a8c1d5b40",
"source": "/warehouse/wes-work-planning",
"type": "com.warehouse.wes.work-planning.workpool.PathCapacityChanged",
"subject": "pick-to-tote",
"time": "2026-08-21T22:40:00Z",
"datacontenttype": "application/json",
"dataschema": "urn:warehouse:wes-work-planning:events:PathCapacityChanged:v1",
"data": {
"path_id": "pick-to-tote",
"cutoff_at": "2026-08-22T02:00:00Z",
"remaining_units": 17,
"known": true
}
}

known is false (and remaining_units is always 0) for a FlowFed path — it has no hard admission ceiling, only a backlog alarm threshold, which is not a capacity figure — or for a ReleaseFed path with no WIP limit provisioned. order-management consumes it through its kafkapathcapacity adapter, which backs its ports.PathCapacity port when order-management runs with PATH_CATALOGUE_SOURCE=kafka (as deployed; without it, that port falls back to the UnknownPathCapacity placeholder), and network-fulfillment keeps an exact (path_id, cutoff_at) cache of it in its pathcapacitycache adapter; see ADR-0018 for the full design, including why correlation runs by cutoff_at timestamp rather than process-path-management's cptId string.

Idempotency​

Kafka is at-least-once, so every consumer path here is idempotent. Before applying an event's effect, its CloudEvents id is inserted into processed_events (Postgres; the in-memory set is a unit-test double only). A primary-key collision means "already processed": the effect is skipped and the message is acked anyway. The insert runs in the same transaction as the effect (ADR-0028). If the effect fails, the mark rolls back with it, so the retry really re-applies the event and a failure that never heals ends in <topic>.dlq.

Consequences worth knowing:

  • Replaying a StockReserved does not double-decrement usable inventory.
  • Replaying a ShiftPlanCommitted does not re-write the labour projection.
  • Replaying a TaskCompleted does not call RecordCompletion twice — so a redelivery never surfaces the aggregate's ErrAlreadyCompleted as a spurious error or a retry loop. The aggregate would reject it anyway; that is defence in depth, not the only net.
  • A TaskCompleted carrying a new event id for a work unit that is already completed is likewise not an error: it is the TaskCompletedAlreadyCompleted skip — INFO-logged, marked processed, neither retried nor dead-lettered (ADR-0043). A second task cannot complete a unit twice; the fact simply no longer applies.

Smoke-testing by hand​

# publish a workforce-shaped CloudEvent onto the shared broker (one line)
echo '{"specversion":"1.0","id":"11111111-1111-4111-8111-111111111111",
"type":"com.warehouse.wes.workforce-management.shiftplan.ShiftPlanCommitted",
"source":"/warehouse/workforce-management","subject":"S1",
"time":"2026-08-23T09:00:00Z","datacontenttype":"application/json",
"dataschema":"urn:warehouse:workforce-management:events:ShiftPlanCommitted:v1",
"data":{"building_id":"BLD1","shift_id":"S1","path_id":"pick-a",
"planned_heads":7,"planned_rate":95.5,"planned_hours":8}}' | tr -d '\n' \
| kafka-console-producer.sh --bootstrap-server localhost:9092 \
--topic warehouse.workforce.events

curl -s localhost:8080/paths/pick-a/labor-plan-view

# watch what this service publishes
kafka-console-consumer.sh --bootstrap-server localhost:9092 \
--topic warehouse.work-planning.events --from-beginning