Domain events
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):
| Attribute | Value |
|---|---|
specversion | 1.0 |
id | a fresh UUID per encoded message — the consumer's dedupe key |
source | /warehouse/labor-performance |
type | com.warehouse.wes.labor-performance.<entity>.<EventName> |
subject | the aggregate instance (see each event) — never empty |
time | the domain event's OccurredAt, UTC |
datacontenttype | application/json |
dataschema | urn: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 type | com.warehouse.wes.labor-performance.standard.LaborStandardDefined |
| Topic | warehouse.labor-performance.analytics and warehouse.labor-performance.events (since ADR 0038) |
| Partition key | task_type (both topics) |
subject | the new standard_id |
dataschema | urn:warehouse:labor-performance:analytics:LaborStandardDefined:v1 on the analytics topic, urn:warehouse:labor-performance:events:LaborStandardDefined:v1 on the integration topic |
| Producer | DefineStandard when no standard was open for the scope (task type, handling unit, site) |
| Consumers | this 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:
| Field | Type | Notes |
|---|---|---|
standard_id | string | shared.StandardId |
task_type | string | PICK, PACK or SLAM |
expected_seconds | integer | > 0 |
effective_from | RFC 3339 timestamp | |
travel_component_seconds | integer | omitted when the standard declares none (ADR 0015) |
handling_unit | string | EACH, CASE or PALLET; omitted for a task-type-only standard (ADR 0035) |
team_lift_threshold_g | integer | CASE standards only; the weight in grams above which a case needs a team lift; omitted when none |
team_lift_expected_seconds | integer | CASE standards only; the team-lift standard time; present only with team_lift_threshold_g |
site_code | string | additive (ADR 0038); 1-32 characters, no whitespace; omitted for a site-less standard (every site) |
LaborStandardRevised
| CE type | com.warehouse.wes.labor-performance.standard.LaborStandardRevised |
| Topic | warehouse.labor-performance.analytics and warehouse.labor-performance.events (since ADR 0038) |
| Partition key | task_type (both topics) |
subject | the new standard_id |
dataschema | urn:warehouse:labor-performance:analytics:LaborStandardRevised:v1 on the analytics topic, urn:warehouse:labor-performance:events:LaborStandardRevised:v1 on the integration topic |
| Producer | DefineStandard when an open standard of the same scope was closed |
| Consumers | this repo's cmd/labor-projector (analytics; counts standards_revised); warehouse-planning (integration) |
| Field | Type | Notes |
|---|---|---|
standard_id | string | the new standard's id |
task_type | string | |
previous_expected_seconds | integer | from the closed standard |
expected_seconds | integer | the new value (NewExpectedSeconds in Go) |
effective_from | RFC 3339 timestamp | also the instant the prior standard closed |
travel_component_seconds | integer | the new standard's value; omitted when none |
handling_unit, team_lift_threshold_g, team_lift_expected_seconds | string, integer, integer | the new standard's values, omitted when none (ADR 0035) |
site_code | string | the 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 type | com.warehouse.wes.labor-performance.performance.TaskPerformanceRecorded |
| Topic | warehouse.labor-performance.analytics |
| Partition key | task_type (empty string when unclassified) |
subject | associate_id, or task_id when there is no associate |
dataschema | urn:warehouse:labor-performance:analytics:TaskPerformanceRecorded:v1 |
| Producer | RecordTaskPerformance (Kafka-driven only) |
| Consumers | this repo's cmd/labor-projector |
TaskPerformanceRecorded (integration)
| CE type | com.warehouse.wes.labor-performance.performance.TaskPerformanceRecorded (same type) |
| Topic | warehouse.labor-performance.events (ADR 0013) |
| Partition key | associate_id (empty string for a robot station) |
subject | associate_id, or task_id when there is no associate |
dataschema | urn:warehouse:labor-performance:events:TaskPerformanceRecorded:v1 |
| Producer | RecordTaskPerformance |
| Consumers | workforce-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:
| Field | Type | Notes |
|---|---|---|
task_id | string | fulfillment-execution's task id |
associate_id | string | empty when the station had no checked-in occupant |
task_type | string | PICK, PACK, SLAM or empty (unclassified) |
efficiency_pct | number or null | null when unscorable — never 0 |
actual_seconds | integer | the upstream duration_seconds; 0 when unmeasurable |
idle_seconds_before | integer or null | additive (ADR 0014); null on first observation, empty associate or out-of-order gap |
completed_at | RFC 3339 timestamp | the consumed event's time |
handling_unit | string | additive (ADR 0035); EACH, CASE or PALLET; omitted when the completion carried no handling unit |
team_lift | boolean | additive (ADR 0035); present only with handling_unit; true when the CASE team-lift standard time scored the task |
Consumed
TaskCompleted (from fulfillment-execution)
| CE type | com.warehouse.wes.fulfillment-execution.task.TaskCompleted |
| Topic | warehouse.fulfillment.events (shared, fan-out with wes-work-planning) |
| Consumer group | labor-performance (KAFKA_CONSUMER_GROUP) |
| Dedupe | CloudEvents id, via processed_events |
| Handler | inbound/kafka.Consumer.handleFulfillmentEvent → RecordTaskPerformance |
| Failure | invalid CloudEvent, or 3 failed attempts → warehouse.fulfillment.events.dlq |
| Field read | Maps to |
|---|---|
id (attribute) | KafkaEventId |
time (attribute) | CompletedAt |
data.task_id | TaskId |
data.associate_id | AssociateId (empty allowed) |
data.duration_seconds | ActualSeconds (0 allowed) |
data.task_type | TaskType 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.