Skip to main content

Domain events

The model view of the events. The wire format, topics, key and payload fields are on the Event catalogue; how a neighbour reacts is on Integration. Event names are past tense, raised by an aggregate command and appended to the outbox in the same transaction (internal/domain/*/events.go, internal/adapters/outbound/kafka/encoder.go).

Source: aggregates internal/domain/{offer,promise,book,policy}; consumers verified in customer-ordering, order-sourcing and node-performance (origin/develop, internal/adapters/inbound/kafka/handlers.go). The analytics events have no consumer and are left out of the arrows.

Published​

EventAggregateMeaningRaised byRecipients
DeliveryOfferQuotedDeliveryOfferAn offer was persisted with its window and witness, the optional capacityBand of its book at quote time (ADR 0023) and, for a CONSOLIDATED offer, consolidationEligible (ADR 0024). One per offer, so one quote can raise several.QuoteDeliveryOffersnone (analytics: quote-to-order conversion per tier and node; promise coverage per region from destinationPostalPrefix, deliverByLatest and timeZone, ADR 0030)
PromiseMadePromiseA provisional promise holds capacity; the offer is consumed. A CONSOLIDATED promise also carries consolidationEligible (ADR 0024).MakePromisenone (analytics)
PromiseConfirmedPromiseThe order was placed; the hold became confirmed. A repeated confirm raises nothing.ConfirmPromisenone (analytics)
PromiseReleasedPromiseA provisional promise's hold expired and was returned (reason: HOLD_EXPIRED).ReleaseExpiredHoldsnone (analytics: hold leakage)
PromiseCancelledPromiseA confirmed or at-risk promise was cancelled and its confirmed hold returned.CancelPromise, OnCustomerOrderCancellednone (analytics)
PromiseAtRiskPromiseThe witness path is no longer feasible (reason names why). A signal, not a verdict.FlagAtRisk in OnDepartureCancelled, OnWaveCancelled, OnBookingFailed, OnBookingMoved, OnPackageExceptionRaised, OnPackageInductionDeferred, OnFulfillmentUnsourceable; also FlagPredictedLate, the clock-driven late-risk sweep, with reason PREDICTED_LATE (ADR 0021)customer-ordering
PromiseRevisedPromiseThe window moved later because the old path broke; carries the previous latest bound and the new terms, node and reason.ReviseAtRiskcustomer-ordering, order-sourcing
PromiseUnkeepablePromiseRe-promising found no path at any tier. At most once per promise.ReviseAtRiskcustomer-ordering
PromiseKeptPromiseDelivered on or before deliverByLatest.JudgePromisecustomer-ordering, node-performance
PromiseBrokenPromiseDelivered late, lost or returned, with cause LATE, LOST or RETURNED and minutes late.JudgePromisecustomer-ordering, node-performance
PromiseBookExhaustedPromiseBookA hold brought the node's cutoff to its share; later quotes find no room there.MakePromiseorder-sourcing
PromisePolicyPublishedPromisePolicyA new immutable policy version is current.PublishPromisePolicynone (analytics)
DeliveryRequestAnswerednone (a best-effort fact, not an aggregate; entity deliveryrequest)A quote or an estimate was answered with 200, with or without a promise: kind, the destination region (first two characters of the postal prefix only), item count, whether a promise came back and the shortest promised day count. Handed over AFTER the response through a bounded queue, dropped and counted when it is full or the write fails, and raised only while DELIVERY_REQUEST_FACTS_ENABLED=true (ADR 0032).the REST adapter of QuoteDeliveryOffers and EstimateDeliveries, after the responsenone (analytics)

Every state change of a promise raises exactly one event, with the single exception of the idempotent repeat of a confirm. The state machine is on Aggregate design canvas.

Consumed​

Each consumed event updates a read model (never an aggregate directly) or runs a policy. Idempotent on the CloudEvents id.

Event (producer)ReactionPolicy or projection
NodeRegistered, NodeOperationalProfileDeclared, NodeActivated, NodeSuspended, NodeRetired (node-topology)upsert the node and profile; a suspended or retired node leaves the candidate set; NodeActivated / NodeSuspended older than the stored StateAt is dropped and an equal instant applies; RETIRED is terminal: no later status fact revives the node (ADR 0029)projection rm_nodes
LaneOpened, LaneClosed, ServiceAreaAssigned, RegionDefined (node-topology)upsert lane, service area, regionprojections
CatalogItemCreated, CatalogItemDiscontinued, ListingCreated, ListingAvailabilityChanged, ListingSuppressed, ListingRestored (offer-availability)upsert item and listing; ListingSuppressed / ListingRestored older than the stored SuppressedAt is dropped, an equal instant applies (ADR 0029)projections
DepartureScheduled, DepartureCapacityChanged (linehaul)upsert the departure and its remaining packages; a capacity event older than the stored CapacityAt is dropped, an equal instant applies (ADR 0028)projection rm_departures
LoadDeparted, LoadArrived (linehaul)LoadDeparted opens the load's pairing row and LoadArrived pairs it into one measured-transit observation; LoadArrived also records the arrival of the load's departure (needs a departureId)projections rm_load_transit_open, rm_transit_actuals (ADR 0014), rm_departure_arrival for the late-risk sweep (ADR 0021)
DepartureCancelled (linehaul)mark the departure unscheduled; flag promises whose witness uses itRepromiseOnRisk
BookingMoved, BookingFailed (linehaul)flag promises that rode the bookingRepromiseOnRisk
DeliveryWaveScheduled, DeliveryWaveCapacityChanged (last-mile)upsert the wave; a capacity event older than the stored CapacityAt is dropped, an equal instant applies (ADR 0028)projection rm_waves
DeliveryWaveCancelled (last-mile)mark cancelled; flag promises whose witness wave it isRepromiseOnRisk
PackageInductionDeferred (last-mile)flag the promiseRepromiseOnRisk
NodeScorecardUpdated (node-performance)upsert the grade when computedAt is not older than the stored one (ADR 0028)projection rm_scorecards
NodeTierEligibilityChanged (node-performance)upsert the (node, tier) fact when changedAt is not older than the stored one; unknown tier or missing field is ignored and countedprojection rm_node_tier_eligibility
FulfillmentLocked, FulfillmentShipped (order-sourcing)record the assignment, then the packages; may complete the facts for judgingJudgeOnDelivery
FulfillmentUnsourceable (order-sourcing)flag the promise at risk and re-promise excluding the listed nodesRepromiseOnRisk
PackageDelivered, PackageLost, PackageReturned (shipping-and-tracking)record the outcome; judge when completeJudgeOnDelivery
PackageExceptionRaised (shipping-and-tracking)flag the promise at riskRepromiseOnRisk
CustomerOrderPlaced (customer-ordering)confirm each group's promise if still provisionalreconciling ConfirmPromise
CustomerOrderCancelled (customer-ordering)cancel the listed groups' promises, or all of themCancelPromise

Source: internal/adapters/inbound/kafka/dispatch.go (Handlers), internal/application/usecases/projections.go. A payload that cannot be applied is dead-lettered, never blocks the partition.

Ordering and delivery guarantees​

  • At-least-once, key = aggregate root id; the relay sends rows in outbox_events.id order.
  • A promise's events share a partition, so a consumer sees PromiseAtRisk before the PromiseRevised that follows it.
  • Producers are not ordered across topics: the read model keeps what it knows, and a late schedule event never undoes a later cancel (scheduled flag handling in projections.go).
  • No event carries personal data: the destination is a postal prefix and ids only.