Skip to main content

Aggregate Design Canvas

As built

Derived from network/model/model.yaml. This context's service is built; the model carries its as-built contracts, and identifiers (Err... names, routes, CloudEvents types) are the names the service uses.

Following the ddd-crew Aggregate Design Canvas v1.1. The model gives this context two aggregate roots: ShippingLabel and PackageJourney. They share the tracking number as a value, never as a reference: a label can be voided without loading the journey, and the journey takes thousands of scans per hour without touching the label row that holds the encrypted address.

ShippingLabel​

1. Name​

ShippingLabel (proposed package internal/domain/label), identified by labelRef.

2. Description​

The label for one package: tracking number, service tier, and the encrypted ship-to snapshot needed to print it. It is the only artefact outside customer-ordering that carries an address. The address is read once, at issue time, from customer-ordering (GetShipTo) and is never published.

3. State Transitions​

Derived from: model.yaml → contexts[shipping-and-tracking].aggregates[ShippingLabel].states, .transitions, .commands.

Omitted: nothing. VOIDED has no outgoing transition in the model, so it is drawn as final. What a void does to the journey of the same tracking number is not modelled (a LABELLED journey has no exit; see the canvas open questions).

4. Enforced Invariants​

InvariantEnforced by
One label per (poNumber, packageNo)ErrLabelAlreadyIssued
One reverse label per (returnAuthorizationId, packageNo) (service ADR 0017)ErrLabelAlreadyIssued
trackingNumber is uniqueErrTrackingNumberTaken
The ship-to address is never published (business decision, no Err... in the model)By construction: no event data, response schema or read model of this context has an address field

5. Corrective Policies​

  • No policy of this context reacts to a label. The model lists only journey policies.
  • Neighbour reactions to LabelIssued: linehaul-transportation adds the package to its ExpectedVolumeView; customer-ordering adds the tracking number to its OrderTrackingView.
  • LabelVoided is an integration event: customer-ordering and linehaul-transportation (ExpectedVolumeView) consume it (contracts-delta E16; apis/asyncapi.yaml), so a void corrects both views.

6. Handled Commands​

CommandIssued byInbound adapter (proposed)
IssueLabelvendor-connectivity, inside a vendor's label requestREST POST /labels (in-org)
IssueReturnLabelcustomer-returns, inside a shopper's return-label request (service ADR 0017)REST POST /return-labels (in-org)
VoidLabelNot named in the modelREST POST /labels/{labelRef}/voids

7. Created Events​

EventRaised whenFull CloudEvents type
LabelIssuedIssueLabel saves an ISSUED labelcom.retailnetwork.logistics.shipping-and-tracking.label.LabelIssued
LabelVoidedVoidLabel moves the label to VOIDEDcom.retailnetwork.logistics.shipping-and-tracking.label.LabelVoided

Subject and Kafka key: labelRef.

8. Throughput​

Estimate (model: "medium"). One write per package at issue, rarely a second at void. The only contention is a retried label request for the same (poNumber, packageNo), resolved by a unique constraint and the Idempotency-Key.

9. Size​

Estimate (model: "one per package"). One row plus one encrypted snapshot. At most two events in its life (LabelIssued, then perhaps LabelVoided).

PackageJourney​

1. Name​

PackageJourney (proposed package internal/domain/journey), identified by trackingNumber.

2. Description​

The customer-visible timeline of one package. It owns its Scan entities (scanId, nodeId, scanType, at) and folds facts from three producers into one forward-only state: the vendor's shipment confirmation and the first pickup scan, linehaul load departures and arrivals, and last-mile out-for-delivery and attempts. It also carries the day-of ETA window (AssignEta, ADR 0013) and the delivery-point flag (FlagDeliveryPoint, ADR 0014), neither of which is a scan: both are stored without moving the state. It ends in DELIVERED, RETURNED or LOST.

3. State Transitions​

Derived from: model.yaml → contexts[shipping-and-tracking].aggregates[PackageJourney].states, .transitions, .commands, .invariants.

Omitted: out-of-order and duplicate scans (they never move the state, see the invariants).

Which fact drives which RecordScan transition. The model gives the transitions and the consumed events, not the mapping between them. This table is the proposed mapping; the rows marked gap depend on information this context does not receive.

Source factJourney state beforeState afterNote
VendorShipmentConfirmed (per tracking number)LABELLEDLABELLEDAn applied SHIPMENT_CONFIRMED scan at the vendor node that moves no state and raises PackageScanned (ADR 0002 A5). Handover is still the network's own scan (HandoverOnFirstScan).
First LoadDeparted naming the tracking numberLABELLEDHANDED_OVERThe pickup departure at the vendor node. Raises PackageHandedOver with handedOverAt = departedAt, nodeId = originNodeId. The event carries departureKind; PICKUP marks the pickup departure (policy ScanTypeFromLoadFacts).
LoadArrived at a sortation centre or air hubHANDED_OVER or IN_TRANSITIN_TRANSIT
Later LoadDepartedIN_TRANSITIN_TRANSIT
LoadArrived at a delivery stationIN_TRANSITAT_STATIONLoadArrived carries nodeType; DELIVERY_STATION is a station arrival. A direct-injection arrival moves HANDED_OVER to AT_STATION (policy ScanTypeFromLoadFacts).
PackageOutForDeliveryAT_STATIONOUT_FOR_DELIVERY
DeliveryAttempted, outcome DELIVEREDOUT_FOR_DELIVERYDELIVEREDRaises PackageDelivered with deliveredAt = at.
DeliveryAttempted, outcome FAILEDOUT_FOR_DELIVERYAT_STATIONThe package goes back to the station for the next wave (last-mile-delivery RetryNextWave).
REST POST /journeys/{trackingNumber}/scansany open stateper the edges aboveCaller not named in the model.

Every applied scan raises PackageScanned with the new state.

4. Enforced Invariants​

InvariantEnforced by
Scans apply in time order; an older scan is stored but does not move the stateErrScanOutOfOrder
A scanId is applied onceErrDuplicateScan
DELIVERED, RETURNED, LOST and VOIDED are terminalErrJourneyClosed
A label is voided only before handover: a void of a journey that is past LABELLED and still open is refusedErrVoidAfterHandover (409 void-after-handover); a void of a closed journey (for example DELIVERED) answers ErrJourneyClosed (409 journey-closed)
The stored ETA window is empty or has etaStart < etaEnd and a non-zero etaAssignedAt; an assignment not strictly newer than the stored one is refused, and a terminal journey refuses AssignEtaErrEtaStale (stale) / ErrJourneyClosed (terminal)
pointFlagReason and pointFlaggedAt are null together and the reason is NOT_HOME or ACCESS_PROBLEM; a flag not strictly newer than the stored one is refused, and a terminal journey refuses FlagDeliveryPointErrPointFlagStale (stale) / ErrJourneyClosed (terminal)
Only the transitions drawn above exist (forward only)The model names no Err... for a scan whose fact has no edge from the current state (for example PackageOutForDelivery on an IN_TRANSIT journey). These pages store such a scan as not applied, like an out-of-order one, and list the missing error as a model gap

5. Corrective Policies​

  • HandoverOnFirstScan (this context): the first pickup-load departure scan at the vendor node is the handover instant used by node-performance.
  • ExceptionOnSilence (this context): no scan within the expected leg time plus a tolerance raises PackageExceptionRaised with reason NO_SCAN. The expected leg time is not available to this context in the model (no departure or lane data is consumed); see the open questions.
  • RepromiseOnRisk (delivery-promise): on PackageExceptionRaised, recompute and revise the promise.
  • JudgeOnDelivery (delivery-promise): on PackageDelivered, judge every promise of the package's group kept or broken.
  • order-sourcing moves the assignment SHIPPED -> DELIVERED (MarkDelivered) on PackageDelivered.
  • RetryNextWave (last-mile-delivery): a failed attempt re-inducts the package into the next wave; the third failure raises PackageReturnInitiated. This context consumes it and runs ReturnToSender on an AT_STATION journey (ADR 0002 A8).
  • Lost sweep (this context): an IN_TRANSIT journey whose NO_SCAN exception stayed unanswered (no applied scan) for 48 hours is declared lost (DeclareLost, ADR 0002 A8).

6. Handled Commands​

CommandIssued byInbound adapter (proposed)
StartJourneyThe IssueLabel use case (no trigger is named in the model)none of its own
RecordScanKafka consumers of VendorShipmentConfirmed, LoadDeparted, LoadArrived, PackageOutForDelivery, DeliveryAttempted; an unnamed REST callerinternal/adapters/inbound/kafka; REST POST /journeys/{trackingNumber}/scans
AssignEtaThe Kafka consumer of StopEtaWindowAssigned (use case ApplyEtaWindows, one unit per event, inbox claim first)internal/adapters/inbound/kafka
FlagDeliveryPointThe Kafka consumer of DeliveryPointFlagged (one unit per event, inbox claim first)internal/adapters/inbound/kafka
RaiseExceptionThe ExceptionOnSilence sweepinternal scheduler
ReturnToSenderThe Kafka consumer of PackageReturnInitiated (last-mile-delivery; ADR 0002 A8)internal/adapters/inbound/kafka
DeclareLostThe silence sweep, 48 h after an unanswered NO_SCAN on an IN_TRANSIT journey (ADR 0002 A8)internal scheduler

7. Created Events​

EventRaised whenFull CloudEvents type
PackageScannedevery applied scancom.retailnetwork.logistics.shipping-and-tracking.journey.PackageScanned
PackageHandedOverLABELLED -> HANDED_OVERcom.retailnetwork.logistics.shipping-and-tracking.journey.PackageHandedOver
PackageDeliveredOUT_FOR_DELIVERY -> DELIVEREDcom.retailnetwork.logistics.shipping-and-tracking.journey.PackageDelivered
PackageExceptionRaisedRaiseException (no transition)com.retailnetwork.logistics.shipping-and-tracking.journey.PackageExceptionRaised
PackageReturnedAT_STATION -> RETURNEDcom.retailnetwork.logistics.shipping-and-tracking.journey.PackageReturned
PackageLostIN_TRANSIT -> LOSTcom.retailnetwork.logistics.shipping-and-tracking.journey.PackageLost
PackageEtaWindowAssignedAssignEta stores a window (no transition)com.retailnetwork.logistics.shipping-and-tracking.journey.PackageEtaWindowAssigned
PackageDeliveryPointFlaggedFlagDeliveryPoint stores a flag (no transition)com.retailnetwork.logistics.shipping-and-tracking.journey.PackageDeliveryPointFlagged

Subject and Kafka key: trackingNumber. A handover or delivery scan raises two events in one transaction: PackageScanned and the milestone event. AssignEta and FlagDeliveryPoint raise theirs in the same unit of work as the stored window or flag, one per journey of the stop. The journey view (GET /journeys/{trackingNumber}, MCP and A2A) shows etaStart and etaEnd only while EtaCurrent holds: the state is OUT_FOR_DELIVERY, the etaAssignedAt is non-zero and not before lastScanAt. The window is shown as received, never clipped to the promised window.

8. Throughput​

Estimate (model: "very high (every scan)"). Writes come from three topics keyed by different ids (poNumber, loadId, routeId), so two consumers can write the same journey at once. The proposed design uses an optimistic version column and retries the command on a conflict. One LoadDeparted or LoadArrived names many tracking numbers and becomes one transaction per journey.

9. Size​

Estimate (model: "one per package + scans"). A typical journey holds one vendor scan, a pickup departure, one to three arrival and departure pairs, an out-for-delivery and one or more attempts: about 6 to 12 scans. Events per journey: one PackageScanned per applied scan, one PackageHandedOver, one terminal event, and zero or more PackageExceptionRaised.

Read models​

Read modelSource eventsUsed forWhy it is not an aggregate
CatalogDimensionsViewoffer-availability CatalogItemCreated (catalogItemId, title, lengthMm, widthMm, heightMm, weightG, hazmat, fragile)Item dimensions, weight and handling flags for the label. The model does not say which command reads it, and no command of this context takes a catalogItemId.It enforces no invariant and accepts no command. It is a local copy of another context's facts, rebuilt by replaying the topic.

GET /journeys/{trackingNumber} reads the PackageJourney itself; it is a query, not a separate read model.