Aggregate Design Canvas
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
| Invariant | Enforced by |
|---|---|
One label per (poNumber, packageNo) | ErrLabelAlreadyIssued |
One reverse label per (returnAuthorizationId, packageNo) (service ADR 0017) | ErrLabelAlreadyIssued |
trackingNumber is unique | ErrTrackingNumberTaken |
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-transportationadds the package to itsExpectedVolumeView;customer-orderingadds the tracking number to itsOrderTrackingView. LabelVoidedis an integration event:customer-orderingandlinehaul-transportation(ExpectedVolumeView) consume it (contracts-delta E16;apis/asyncapi.yaml), so a void corrects both views.
6. Handled Commands
| Command | Issued by | Inbound adapter (proposed) |
|---|---|---|
IssueLabel | vendor-connectivity, inside a vendor's label request | REST POST /labels (in-org) |
IssueReturnLabel | customer-returns, inside a shopper's return-label request (service ADR 0017) | REST POST /return-labels (in-org) |
VoidLabel | Not named in the model | REST POST /labels/{labelRef}/voids |
7. Created Events
| Event | Raised when | Full CloudEvents type |
|---|---|---|
LabelIssued | IssueLabel saves an ISSUED label | com.retailnetwork.logistics.shipping-and-tracking.label.LabelIssued |
LabelVoided | VoidLabel moves the label to VOIDED | com.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 fact | Journey state before | State after | Note |
|---|---|---|---|
VendorShipmentConfirmed (per tracking number) | LABELLED | LABELLED | An 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 number | LABELLED | HANDED_OVER | The 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 hub | HANDED_OVER or IN_TRANSIT | IN_TRANSIT | |
Later LoadDeparted | IN_TRANSIT | IN_TRANSIT | |
LoadArrived at a delivery station | IN_TRANSIT | AT_STATION | LoadArrived carries nodeType; DELIVERY_STATION is a station arrival. A direct-injection arrival moves HANDED_OVER to AT_STATION (policy ScanTypeFromLoadFacts). |
PackageOutForDelivery | AT_STATION | OUT_FOR_DELIVERY | |
DeliveryAttempted, outcome DELIVERED | OUT_FOR_DELIVERY | DELIVERED | Raises PackageDelivered with deliveredAt = at. |
DeliveryAttempted, outcome FAILED | OUT_FOR_DELIVERY | AT_STATION | The package goes back to the station for the next wave (last-mile-delivery RetryNextWave). |
REST POST /journeys/{trackingNumber}/scans | any open state | per the edges above | Caller not named in the model. |
Every applied scan raises PackageScanned with the new state.
4. Enforced Invariants
| Invariant | Enforced by |
|---|---|
| Scans apply in time order; an older scan is stored but does not move the state | ErrScanOutOfOrder |
A scanId is applied once | ErrDuplicateScan |
DELIVERED, RETURNED, LOST and VOIDED are terminal | ErrJourneyClosed |
A label is voided only before handover: a void of a journey that is past LABELLED and still open is refused | ErrVoidAfterHandover (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 AssignEta | ErrEtaStale (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 FlagDeliveryPoint | ErrPointFlagStale (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 bynode-performance.ExceptionOnSilence(this context): no scan within the expected leg time plus a tolerance raisesPackageExceptionRaisedwith reasonNO_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): onPackageExceptionRaised, recompute and revise the promise.JudgeOnDelivery(delivery-promise): onPackageDelivered, judge every promise of the package's group kept or broken.order-sourcingmoves the assignmentSHIPPED -> DELIVERED(MarkDelivered) onPackageDelivered.RetryNextWave(last-mile-delivery): a failed attempt re-inducts the package into the next wave; the third failure raisesPackageReturnInitiated. This context consumes it and runsReturnToSenderon anAT_STATIONjourney (ADR 0002 A8).- Lost sweep (this context): an
IN_TRANSITjourney whoseNO_SCANexception stayed unanswered (no applied scan) for 48 hours is declared lost (DeclareLost, ADR 0002 A8).
6. Handled Commands
| Command | Issued by | Inbound adapter (proposed) |
|---|---|---|
StartJourney | The IssueLabel use case (no trigger is named in the model) | none of its own |
RecordScan | Kafka consumers of VendorShipmentConfirmed, LoadDeparted, LoadArrived, PackageOutForDelivery, DeliveryAttempted; an unnamed REST caller | internal/adapters/inbound/kafka; REST POST /journeys/{trackingNumber}/scans |
AssignEta | The Kafka consumer of StopEtaWindowAssigned (use case ApplyEtaWindows, one unit per event, inbox claim first) | internal/adapters/inbound/kafka |
FlagDeliveryPoint | The Kafka consumer of DeliveryPointFlagged (one unit per event, inbox claim first) | internal/adapters/inbound/kafka |
RaiseException | The ExceptionOnSilence sweep | internal scheduler |
ReturnToSender | The Kafka consumer of PackageReturnInitiated (last-mile-delivery; ADR 0002 A8) | internal/adapters/inbound/kafka |
DeclareLost | The silence sweep, 48 h after an unanswered NO_SCAN on an IN_TRANSIT journey (ADR 0002 A8) | internal scheduler |
7. Created Events
| Event | Raised when | Full CloudEvents type |
|---|---|---|
PackageScanned | every applied scan | com.retailnetwork.logistics.shipping-and-tracking.journey.PackageScanned |
PackageHandedOver | LABELLED -> HANDED_OVER | com.retailnetwork.logistics.shipping-and-tracking.journey.PackageHandedOver |
PackageDelivered | OUT_FOR_DELIVERY -> DELIVERED | com.retailnetwork.logistics.shipping-and-tracking.journey.PackageDelivered |
PackageExceptionRaised | RaiseException (no transition) | com.retailnetwork.logistics.shipping-and-tracking.journey.PackageExceptionRaised |
PackageReturned | AT_STATION -> RETURNED | com.retailnetwork.logistics.shipping-and-tracking.journey.PackageReturned |
PackageLost | IN_TRANSIT -> LOST | com.retailnetwork.logistics.shipping-and-tracking.journey.PackageLost |
PackageEtaWindowAssigned | AssignEta stores a window (no transition) | com.retailnetwork.logistics.shipping-and-tracking.journey.PackageEtaWindowAssigned |
PackageDeliveryPointFlagged | FlagDeliveryPoint 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 model | Source events | Used for | Why it is not an aggregate |
|---|---|---|---|
CatalogDimensionsView | offer-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.