Skip to main content

Domain events

Synced from labor-performance

This page is a copy of docs/docs/ddd/domain-events.md on develop, derived from that repository's code. Edit it there, then re-sync.

Every Kafka message this service produces or consumes is a CloudEvents 1.0 event in structured content mode (ADR 0021): the whole event — attributes and data — is the JSON message value, and the Kafka header content-type is application/cloudevents+json; charset=UTF-8. Events are built and decoded only by internal/adapters/kafka/cloudevents (sdk-go v2 event); transport is kafka-go. There is no flat envelope and no binary mode.

Attributes set on every published event (cloudevents.New):

AttributeValue
specversion1.0
ida fresh UUID per encoded message — the consumer's dedupe key
source/warehouse/labor-performance
typecom.warehouse.wes.labor-performance.<entity>.<EventName>
subjectthe aggregate instance (see each event) — never empty
timethe domain event's OccurredAt, UTC
datacontenttypeapplication/json
dataschemaurn:warehouse:labor-performance:<stream>:<EventName>:v1, stream = analytics or events

The domain event is raised inside the use case's unit of work. It is encoded into outbox_events in the same transaction and published by the always-on outbox relay (ADR 0010). There is no direct-to-Kafka path and no log-only mode (ADR 0034).

Published​

LaborStandardDefined​

CE typecom.warehouse.wes.labor-performance.standard.LaborStandardDefined
Topicwarehouse.labor-performance.analytics and warehouse.labor-performance.events (since ADR 0038)
Partition keytask_type (both topics)
subjectthe new standard_id
dataschemaurn:warehouse:labor-performance:analytics:LaborStandardDefined:v1 on the analytics topic, urn:warehouse:labor-performance:events:LaborStandardDefined:v1 on the integration topic
ProducerDefineStandard when no standard was open for the scope (task type, handling unit, site)
Consumersthis repo's cmd/labor-projector (analytics; counts standards_defined); warehouse-planning (integration; keeps a local copy of the standards, ADR 0038)

Both copies carry the same data, but each is a separate CloudEvent with its own id:

FieldTypeNotes
standard_idstringshared.StandardId
task_typestringPICK, PACK or SLAM
expected_secondsinteger> 0
effective_fromRFC 3339 timestamp
travel_component_secondsintegeromitted when the standard declares none (ADR 0015)
handling_unitstringEACH, CASE or PALLET; omitted for a task-type-only standard (ADR 0035)
team_lift_threshold_gintegerCASE standards only; the weight in grams above which a case needs a team lift; omitted when none
team_lift_expected_secondsintegerCASE standards only; the team-lift standard time; present only with team_lift_threshold_g
site_codestringadditive (ADR 0038); 1-32 characters, no whitespace; omitted for a site-less standard (every site)

LaborStandardRevised​

CE typecom.warehouse.wes.labor-performance.standard.LaborStandardRevised
Topicwarehouse.labor-performance.analytics and warehouse.labor-performance.events (since ADR 0038)
Partition keytask_type (both topics)
subjectthe new standard_id
dataschemaurn:warehouse:labor-performance:analytics:LaborStandardRevised:v1 on the analytics topic, urn:warehouse:labor-performance:events:LaborStandardRevised:v1 on the integration topic
ProducerDefineStandard when an open standard of the same scope was closed
Consumersthis repo's cmd/labor-projector (analytics; counts standards_revised); warehouse-planning (integration)
FieldTypeNotes
standard_idstringthe new standard's id
task_typestring
previous_expected_secondsintegerfrom the closed standard
expected_secondsintegerthe new value (NewExpectedSeconds in Go)
effective_fromRFC 3339 timestampalso the instant the prior standard closed
travel_component_secondsintegerthe new standard's value; omitted when none
handling_unit, team_lift_threshold_g, team_lift_expected_secondsstring, integer, integerthe new standard's values, omitted when none (ADR 0035)
site_codestringthe new (and closed) standard's site, omitted when site-less (ADR 0038); a revision closes only the standard of the same task type, handling unit and site

TaskPerformanceRecorded (analytics)​

CE typecom.warehouse.wes.labor-performance.performance.TaskPerformanceRecorded
Topicwarehouse.labor-performance.analytics
Partition keytask_type (empty string when unclassified)
subjectassociate_id, or task_id when there is no associate
dataschemaurn:warehouse:labor-performance:analytics:TaskPerformanceRecorded:v1
ProducerRecordTaskPerformance (Kafka-driven only)
Consumersthis repo's cmd/labor-projector

TaskPerformanceRecorded (integration)​

CE typecom.warehouse.wes.labor-performance.performance.TaskPerformanceRecorded (same type)
Topicwarehouse.labor-performance.events (ADR 0013)
Partition keyassociate_id (empty string for a robot station)
subjectassociate_id, or task_id when there is no associate
dataschemaurn:warehouse:labor-performance:events:TaskPerformanceRecorded:v1
ProducerRecordTaskPerformance
Consumersworkforce-management (internal/adapters/outbound/laborperformancecache/consumer.go, LABOR_PERFORMANCE_MODE=kafka-cache)

Both TaskPerformanceRecorded messages carry the same data, but each is a separate CloudEvent with its own id:

FieldTypeNotes
task_idstringfulfillment-execution's task id
associate_idstringempty when the station had no checked-in occupant
task_typestringPICK, PACK, SLAM or empty (unclassified)
efficiency_pctnumber or nullnull when unscorable — never 0
actual_secondsintegerthe upstream duration_seconds; 0 when unmeasurable
idle_seconds_beforeinteger or nulladditive (ADR 0014); null on first observation, empty associate or out-of-order gap
completed_atRFC 3339 timestampthe consumed event's time
handling_unitstringadditive (ADR 0035); EACH, CASE or PALLET; omitted when the completion carried no handling unit
team_liftbooleanadditive (ADR 0035); present only with handling_unit; true when the CASE team-lift standard time scored the task

Consumed​

TaskCompleted (from fulfillment-execution)​

CE typecom.warehouse.wes.fulfillment-execution.task.TaskCompleted
Topicwarehouse.fulfillment.events (shared, fan-out with wes-work-planning)
Consumer grouplabor-performance (KAFKA_CONSUMER_GROUP)
DedupeCloudEvents id, via processed_events
Handlerinbound/kafka.Consumer.handleFulfillmentEvent → RecordTaskPerformance
Failureinvalid CloudEvent, or 3 failed attempts → warehouse.fulfillment.events.dlq
Field readMaps to
id (attribute)KafkaEventId
time (attribute)CompletedAt
data.task_idTaskId
data.associate_idAssociateId (empty allowed)
data.duration_secondsActualSeconds (0 allowed)
data.task_typeTaskType via shared.ParseTaskTypeLenient
data.handling_unit (optional, ADR 0035)HandlingUnit via shared.ParseHandlingUnitLenient; absent or unrecognised is "no handling unit"
data.weight_g (optional, ADR 0035)WeightG; absent, non-integer or non-positive is unknown, never a team lift

fulfillment-execution's TaskCompleted v1 does not publish handling_unit or weight_g today; until it does, every completion is scored against the task-type-only standard exactly as before.

data.station_id and data.work_unit_id are decoded but unused. Every other CloudEvents type on the shared topic is committed and ignored.

Own analytics events (projector)​

cmd/labor-projector consumes warehouse.labor-performance.analytics with group labor-performance-analytics from the earliest offset, and folds the three types above into labor_performance_rollup. It reads task_type, expected_seconds, effective_from, actual_seconds, efficiency_pct and completed_at; an empty task_type becomes UNCLASSIFIED.

Dead-letter topic​

warehouse.fulfillment.events.dlq receives the original message bytes and headers plus x-dlq-source-topic, x-dlq-error and x-dlq-failed-at (ADR 0017). It is not a CloudEvent of its own and has no consumer in the fleet.

Source: internal/domain/shared/events.go, internal/adapters/kafka/cloudevents/cloudevents.go, internal/adapters/outbound/kafka/analytics_publisher.go, internal/adapters/outbound/kafka/integration_publisher.go, internal/adapters/inbound/kafka/consumer.go, internal/adapters/inbound/kafka/analytics_consumer.go, apis/asyncapi.yaml, cmd/labor/main.go.