Skip to main content

Domain Events

Synced from process-path-management

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 event this context publishes, with its full CloudEvents 1.0 type, topic, partition key, payload, producing use case and known consumers. Part of the DDD artifact pack.

Envelope (all events)​

Every message is a CloudEvents 1.0 event in structured content mode (the Kafka value is the JSON event; ADR 0016), built only by internal/adapters/kafka/cloudevents.New:

AttributeValue
specversion1.0
idUUID minted once per occurrence (uuid.NewString), shared by the integration and analytics copies and stable across outbox redelivery
source/warehouse/process-path-management
typecom.warehouse.wes.process-path-management.<entity>.<EventName>
subjectaggregate id — path_id, site_id or flow_id; equal to the Kafka key
timethe domain event's At, UTC
datacontenttypeapplication/json
dataschemaurn:warehouse:process-path-management:events:<EventName>:v1 (integration) or urn:warehouse:process-path-management:analytics:<EventName>:v1 (analytics)
Kafka headerscontent-type: application/cloudevents+json; charset=UTF-8 on every message; plus traceparent (and tracestate when set) when the event was raised inside a traced operation — captured at enqueue time and stored on the outbox row (ADR 0027). Baggage is never propagated; an untraced event carries neither header.

Topics: warehouse.process-path-management.events (integration) and warehouse.process-path-management.analytics (analytics, ADR 0007). Every event a use case raises through DefinePath, RevisePath, DeactivatePath, DefineCPTSchedule, DefineProcessFlow or RetireProcessFlow is written to both, in one outbox transaction (Postgres is mandatory, ADR 0037). The start-up catalogue republish (usecases.RepublishCatalogue, ADR 0038) is the exception: it writes to the integration topic only. Writers use the kafkago.Hash balancer (ADR 0013), so all events with the same key land on the same partition.

Published events​

EventFull CloudEvents typePartition key / subjectProducer use caseKnown consumers
ProcessPathCreatedcom.warehouse.wes.process-path-management.processpath.ProcessPathCreatedpath_idusecases.DefinePathfulfillment-execution, wes-work-planning, workforce-management, order-management, network-fulfillment; own pathmgmt-projector (analytics)
ProcessPathUpdatedcom.warehouse.wes.process-path-management.processpath.ProcessPathUpdatedpath_idusecases.RevisePath (only when Revise returns changed=true); also usecases.RepublishCatalogue, one per ACTIVE path at every start, integration topic onlysame five; own projector (not for the republished ones)
ProcessPathDeactivatedcom.warehouse.wes.process-path-management.processpath.ProcessPathDeactivatedpath_idusecases.DeactivatePath (only on an Active path)same five; own projector
CPTScheduleChangedcom.warehouse.wes.process-path-management.cptschedule.CPTScheduleChangedsite_idusecases.DefineCPTSchedule (first define, or a revise with changed=true); also usecases.RepublishCatalogue, one per site at every start, integration topic onlyorder-management, network-fulfillment, dock-scheduling, outbound-shipping; own projector skips it
ProcessFlowDefinedcom.warehouse.wes.process-path-management.processflow.ProcessFlowDefinedflow_idusecases.DefineProcessFlow (first define, version 1)warehouse-planning (the consumer named in ADR 0042; its side is owned by that repo); own projector skips it
ProcessFlowRevisedcom.warehouse.wes.process-path-management.processflow.ProcessFlowRevisedflow_idusecases.DefineProcessFlow (only when Revise returns changed=true); also usecases.RepublishCatalogue, one per ACTIVE flow at every start with the current state and version, integration topic onlysame; own projector skips it
ProcessFlowRetiredcom.warehouse.wes.process-path-management.processflow.ProcessFlowRetiredflow_idusecases.RetireProcessFlow (only on the first retirement)same; own projector skips it

A ProcessPathUpdated, CPTScheduleChanged or ProcessFlowRevised on the integration topic can therefore be a republish of an unchanged path, schedule or flow (new CloudEvents id, same type and data); consumers upsert it, and nothing should count it as a revision. See Use cases.

ProcessPathCreated / ProcessPathUpdated — data​

Go type kafka.ProcessPathData (internal/adapters/outbound/kafka/publisher.go); schema ProcessPathData in apis/asyncapi.yaml.

FieldTypeNotes
path_idstringalways present
match_prefixstringomitempty
directbooleanomitempty — absent when false; consumers must default it to false
required_capabilitiesstring arrayomitempty
destination_location_rolestringDrop / WorkCenter / Shipping; absent when unset (ADR 0009)
cycle_time_p95stringGo duration, e.g. 2h0m0s (ADR 0010)
eligibilityobjectalways present on Created/Updated, {} when fully permissive
eligibility.max_units_per_lineintegerabsent = unbounded
eligibility.required_product_attributesstring arrayomitempty
eligibility.excluded_product_attributesstring arrayomitempty
eligibility.non_sortablebooleanomitempty
intakestring arraydemand sources allowed to route work onto the path: CUSTOMER_ORDER, STOCK_TRANSFER, SLOT_RELOCATION, INVENTORY_CONTROL, REPLENISHMENT (ADR 0034); always present on Created/Updated, [] when only an explicit path id reaches the path; canonical (sorted) order

ProcessPathUpdated carries the full current definition (not a diff); destination_location_role is repeated unchanged because it is never revisable.

ProcessPathDeactivated — data​

Only path_id. Every definition field is omitted, not zeroed.

CPTScheduleChanged — data​

Go type kafka.CPTScheduleData; built from cptschedule.ToSnapshot.

FieldTypeNotes
site_idstring
timezonestringIANA zone
cutoffs[]arrayfull snapshot, never a diff
cutoffs[].cpt_idstringunique within the site
cutoffs[].local_timestringHH:MM
cutoffs[].days_of_weekstring arrayMon..Sun
cutoffs[].ship_methodstring
cutoffs[].eligible_path_idsstring arrayActive paths at write time

ProcessFlowDefined / ProcessFlowRevised / ProcessFlowRetired — data​

Go type kafka.ProcessFlowData, the same shape for all three, built from processflow.State; schema in apis/asyncapi.yaml. Always the full state of the flow at one version, never a diff.

FieldTypeNotes
flow_idstringequals the Kafka key and the CloudEvents subject
namestring
stages[]arrayin flow order; the array order IS the order of the stages
stages[].path_idstringan Active path of this catalogue at write time
stages[].process_typestringPICK, REBIN, PACK, SLAM, DISPATCH, ARRIVAL, RELOCATE, REPLENISH
statusstringACTIVE, or RETIRED on ProcessFlowRetired
versioninteger1 on ProcessFlowDefined, +1 per accepted change (a revision that changes something, or the retirement). A consumer applies a message only when its version is greater than the one it holds, so a republish and a redelivery are no-ops for a consumer that is caught up

Unlike the version column of the other aggregates, which is storage metadata, this version is part of the published contract (ADR 0042).

Events NOT raised​

  • A no-op PUT /process-paths/{pathId} (identical matchPrefix, requiredCapabilities, cycleTimeP95, eligibility, intake) raises nothing.
  • DELETE on an already-deactivated path raises nothing (204).
  • A PUT /sites/{siteId}/cpt-schedule identical to the stored schedule raises nothing.
  • A PUT /process-flows/{flowId} that changes neither the name nor the stages raises nothing and keeps the version; DELETE on an already retired flow raises nothing (204).
  • Read operations (REST GET, every MCP tool and A2A skill) never raise events.

Consumed events​

This context consumes no other context's events. Its only consumer, internal/adapters/inbound/kafka.AnalyticsConsumer (run by cmd/pathmgmt-projector, group process-path-management-analytics, StartOffset: FirstOffset), reads its own analytics topic:

TypeEffect
...processpath.ProcessPathCreatedcatalogue_growth_rollup.paths_defined += 1 for the UTC day bucket
...processpath.ProcessPathUpdatedpaths_revised += 1
...processpath.ProcessPathDeactivatedpaths_deactivated += 1
...cptschedule.CPTScheduleChanged, the three ...processflow.ProcessFlow* types and any unknown typecommitted and skipped
non-CloudEvents messagedead-lettered to warehouse.process-path-management.analytics.dlq, then committed
projecting type whose claim+apply step still fails after maxAnalyticsHandlerAttempts (3)dead-lettered to the same DLQ, then committed (ADR 0012, ADR 0032)

Dedupe is on the CloudEvents id, twice: analytics_consumed_events (consumer gate) and analytics_processed_events (claimed inside the projection transaction). Both claims and the rollup upsert commit in ONE analytics transaction (ADR 0032), so a projector stop between the claim and the apply leaves no claim and the redelivery applies the event exactly once.

Delivery guarantees​

  • Atomic with state (Postgres mode): OutboxPublisher.Publish inserts one outbox_events row per topic inside the use case's UnitOfWork transaction (ADR 0003).
  • At-least-once to Kafka: OutboxRelay sends rows in id order with RequiredAcks: RequireAll and marks them published afterwards; a crash between send and mark re-sends with the same id.
  • Per-aggregate order: same key → same partition (Hash balancer); the relay stops a pass at the first failed send so later rows never overtake it.

Source: internal/domain/shared/events.go, internal/domain/cptschedule/events.go, internal/domain/processflow/events.go, internal/adapters/outbound/kafka/process_flow_events.go, internal/adapters/outbound/kafka/publisher.go, internal/adapters/outbound/kafka/analytics_publisher.go, internal/adapters/outbound/kafka/writer_config.go, internal/adapters/kafka/cloudevents/cloudevents.go, internal/adapters/kafka/cloudevents/types.go, internal/adapters/outbound/postgres/outbox_publisher.go, internal/adapters/outbound/postgres/outbox_relay.go, internal/adapters/inbound/kafka/analytics_consumer.go, apis/asyncapi.yaml.