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. Three aggregate roots: VendorAccount, PurchaseOrder and Submission. Proposed Go packages are internal/domain/vendor, internal/domain/po and internal/domain/submission.

VendorAccount​

1. Name​

VendorAccount (vendor.VendorAccount), identified by vendorId.

2. Description​

A vendor organisation, its ack window, rate limits and the nodes it may operate. The ack window feeds every purchase order's ackBy. The nodes a vendor may operate come from the VendorNodeView read model (fed by node-topology), not from a collection inside the aggregate.

3. State Transitions​

Derived from: model.yaml → contexts[vendor-connectivity].aggregates[VendorAccount].states, .transitions, .commands.

Omitted: nothing. The model has no terminal state; a vendor is never deleted.

4. Enforced Invariants​

InvariantEnforced by
ackWindow is between 1h and 24hErrAckWindowOutOfRange
A vendor acts only on its own nodesErrNodeNotOwnedByVendor (checked against VendorNodeView on every node-scoped and PO-scoped write)
A suspended vendor's writes are refusedErrVendorSuspended (409 vendor-suspended)

5. Corrective Policies​

None. A SUSPENDED vendor's writes (acknowledgement, inventory, node registration, node profile, label request, shipment confirmation, inbound receipt) are refused with ErrVendorSuspended; reads, polling, new purchase orders, the expiry sweep and submissions already received continue (service ADR 0002 A9).

6. Handled Commands​

CommandIssued byChannel
OnboardVendorNetwork partner managerREST POST /vendors
SuspendVendorNetwork partner managerREST POST /vendors/{vendorId}/suspensions
ReinstateVendorNetwork partner managerREST POST /vendors/{vendorId}/reinstatements

7. Created Events​

EventRaised whenFull CloudEvents type
VendorOnboardedOnboardVendor succeedscom.retailnetwork.partner.vendor-connectivity.vendoraccount.VendorOnboarded
VendorSuspendedSuspendVendor succeedscom.retailnetwork.partner.vendor-connectivity.vendoraccount.VendorSuspended
VendorReinstatedReinstateVendor succeedscom.retailnetwork.partner.vendor-connectivity.vendoraccount.VendorReinstated

SuspendVendor raises VendorSuspended and ReinstateVendor raises VendorReinstated; a repeat of either is a no-op that raises nothing (service ADR 0002 A8).

8. Throughput​

Estimate: rare. Onboarding and suspension are human acts.

9. Size​

Estimate: tens of vendors. One small row each; one event in its life.

PurchaseOrder​

1. Name​

PurchaseOrder (po.PurchaseOrder), identified by poNumber. poNumber is idempotent on assignmentId + releaseNo.

2. Description​

The network's instruction to one vendor node to ship one shipment group in full by requiredShipBy. It owns the protocol and its clock: the deadline ackBy, the single whole-order acknowledgement, the label gate and the shipment confirmation. Value objects: PoLine{lineNo, listingId, quantity}, AckDecision(ACCEPT|REJECT){reasonCode}, Label{labelRef, trackingNumber, carrier}, RejectReason(OUT_OF_STOCK|UNKNOWN_LISTING|CANNOT_MEET_SHIP_BY|DISCONTINUED).

3. State Transitions​

Derived from: model.yaml → contexts[vendor-connectivity].aggregates[PurchaseOrder].states, .transitions, .commands.

Omitted: RequestLabel, which changes no state (it adds Labels to an ACCEPTED order). The qualifiers after ProcessSubmission (outcome and decision) say which of the model's three ACK_PROCESSING transitions applies; the model lists the transitions without naming the condition.

4. Enforced Invariants​

InvariantEnforced by
An acknowledgement covers every line with one decision (fill-or-kill)ErrPartialAcknowledgement
Acknowledged at most once (an acknowledgement still processing counts)ErrAlreadyAcknowledged
No acknowledgement after ackBy (judged on the receipt instant)ErrAckWindowClosed
No label before ACCEPTEDErrLabelBeforeAcceptance
No shipment confirmation without a label for every packageErrConfirmWithoutLabel
Cancel only while ISSUEDErrCancelAfterAcknowledgement for an order past acknowledgement; an EXPIRED or CANCELLED order is ErrIllegalTransition (same observable result: logged, acknowledged)
ackBy = min(issuedAt + ackWindow, requiredShipBy - handlingTime), fixed at issuecomputed by IssuePurchaseOrder from the handlingTimeMinutes of VendorNodeView; a business decision, no Err... in the model

5. Corrective Policies​

PolicyRule (from the model)Effect on this aggregate
IssueOnReleaseOn FulfillmentReleasedToNode for a VENDOR node, issue a purchase order (poNumber idempotent on assignmentId + releaseNo)IssuePurchaseOrder
CancelOnSourcingCancelOn FulfillmentCancelled, cancel the ISSUED purchase order of that releaseCancelPurchaseOrder; refused after acknowledgement
CancelOnReleaseWithdrawnOn FulfillmentReleaseWithdrawn (a consolidation merge dissolved by a promise revision), cancel the ISSUED purchase order of that releaseNoCancelPurchaseOrder; refused after acknowledgement, logged and acknowledged
ExpireUnacknowledgedSweep: ISSUED past ackBy becomes EXPIREDExpireUnacknowledgedOrders
SimulationKnobsPO_REDELIVERY_RATE re-delivers purchase orders on pollNone on state; vendors must be idempotent on poNumber
order-sourcing ReassignOnRefusal (neighbour)On PurchaseOrderRejected or PurchaseOrderExpired, exclude the node and re-queueA later release may issue a new purchase order to another node
order-sourcing LockOnCommit (neighbour)On PurchaseOrderAccepted, lock the assignmentNone here; the accepted order is the path lock

6. Handled Commands​

CommandIssued byChannel
IssuePurchaseOrderpolicy IssueOnReleaseKafka FulfillmentReleasedToNode
SubmitAcknowledgementvendorVendor API POST /vendor/acknowledgements
RequestLabelvendorVendor API POST /vendor/shipping-labels
SubmitShipmentConfirmationvendorVendor API POST /vendor/shipment-confirmations
ExpireUnacknowledgedOrderspolicy ExpireUnacknowledged (sweep)internal timer
CancelPurchaseOrderpolicy CancelOnSourcingCancel, policy CancelOnReleaseWithdrawnKafka FulfillmentCancelled, FulfillmentReleaseWithdrawn
ProcessSubmission (transitions only)the submission processorinternal, after notBefore

7. Created Events​

EventRaised whenFull CloudEvents type
PurchaseOrderIssuedIssuePurchaseOrdercom.retailnetwork.partner.vendor-connectivity.purchaseorder.PurchaseOrderIssued
PurchaseOrderAcceptedACK_PROCESSING to ACCEPTEDcom.retailnetwork.partner.vendor-connectivity.purchaseorder.PurchaseOrderAccepted
PurchaseOrderRejectedACK_PROCESSING to REJECTEDcom.retailnetwork.partner.vendor-connectivity.purchaseorder.PurchaseOrderRejected
PurchaseOrderExpiredISSUED to EXPIREDcom.retailnetwork.partner.vendor-connectivity.purchaseorder.PurchaseOrderExpired
PurchaseOrderCancelledISSUED to CANCELLEDcom.retailnetwork.partner.vendor-connectivity.purchaseorder.PurchaseOrderCancelled
VendorShipmentConfirmedSHIPMENT_PROCESSING to SHIPPEDcom.retailnetwork.partner.vendor-connectivity.purchaseorder.VendorShipmentConfirmed

Moves to ACK_PROCESSING and SHIPMENT_PROCESSING, and a failed transaction's move back, raise no PurchaseOrder... event; the Submission raises SubmissionProcessed for the latter.

8. Throughput​

Estimate: medium; polling reads dominate. Writes per order: one issue, one or more acknowledgement attempts (a failed transaction returns it to ISSUED), one label request per package batch, one or more shipment confirmation attempts. Concurrency is real: the vendor's write, the expiry sweep, a cancellation and the submission processor can touch the same order within seconds, so the proposed row carries a version for optimistic concurrency.

9. Size​

Estimate: one row per release to a vendor node, plus a handful of lines and one label per package. Lifetime: from issue to SHIPPED (hours to days) or to a terminal refusal. Events per instance: 2 to 3 (issued, then accepted and shipped, or rejected, expired or cancelled).

Submission​

1. Name​

Submission (submission.Submission), identified by transactionId.

2. Description​

One asynchronous vendor write (acknowledgement, inventory feed, node registration, profile declaration, shipment confirmation) and its processing outcome. Value objects: SubmissionKind(ACKNOWLEDGEMENT|INVENTORY|NODE_REGISTRATION|NODE_PROFILE|SHIPMENT_CONFIRMATION), SubmissionError{code, message, path}. It is what GET /vendor/transactions/{transactionId} returns.

3. State Transitions​

Derived from: model.yaml → contexts[vendor-connectivity].aggregates[Submission].states, .transitions, .commands.

Omitted: nothing. A retry by the vendor is a new submission with a new transactionId (unless it reuses the Idempotency-Key, which returns the first one).

4. Enforced Invariants​

InvariantEnforced by
The outcome is set onceErrSubmissionAlreadyProcessed
Processing never starts before notBefore = receivedAt + TX_PROCESSING_DELAYErrSubmissionNotDue

5. Corrective Policies​

  • SimulationKnobs: TX_PROCESSING_DELAY sets notBefore; TX_FAILURE_RATE makes a share of processed submissions end in FAILURE.
  • A downstream refusal (node-topology, offer-availability) ends the submission in FAILURE with the owner's Err... code in SubmissionError.code. A downstream outage leaves it PROCESSING for the next processor pass (proposed).

6. Handled Commands​

CommandIssued byChannel
ReceiveSubmissionevery asynchronous vendor writeVendor API POST /vendor/acknowledgements, POST /vendor/inventory, POST /vendor/nodes, PUT /vendor/nodes/{nodeId}/profile, POST /vendor/shipment-confirmations
ProcessSubmissionthe submission processorinternal, after notBefore

7. Created Events​

EventRaised whenFull CloudEvents type
SubmissionProcessedPROCESSING to SUCCESS or FAILUREcom.retailnetwork.partner.vendor-connectivity.submission.SubmissionProcessed

8. Throughput​

Estimate: medium-high. One submission per vendor write; inventory feeds per node every few minutes dominate.

9. Size​

Estimate: retained 30 days. A submission is small: kind, status, a payload reference and zero or more errors. One event in its life.

Read models​

Read modelSource eventsUsed forWhy it is not an aggregate
VendorNodeViewnode-topology NodeRegistered, NodeActivated, NodeSuspended, NodeRetiredWhich vendor owns a node (ErrNodeNotOwnedByVendor), whether a release targets a VENDOR node (IssueOnRelease), GET /vendor/nodes/{nodeId}node-topology owns the node; this is a local, event-fed copy with no rules of its own
ListingViewoffer-availability ListingCreatedChecking that inventory lines and PO lines name listings of the nodeoffer-availability owns the listing; this context only looks it up

Inbound receipts​

Built, ADR 0009 as realized by vendor-connectivity ADR 0005 (inbound shipments, inbound receipts and catalogue packaging). This section is the delta the seller-inbound design added to this page; where the service decided differently, the text below says so.

Submission gains the kind INBOUND_RECEIPT and the command SubmitInboundReceipt (REST POST /vendor/inbound-receipts, 202 and a transactionId, like every vendor write). An INBOUND_RECEIPT names a shipment in InboundShipmentView addressed to a node of the submitting vendor: as built an unknown vendor, shipment or node is ErrNotFound (404 not-found; the design named it ErrUnknownInboundShipment), and ErrNodeNotOwnedByVendor still applies to the node. New event InboundReceiptSubmitted, appended to the outbox in the same unit of work that accepts the submission, so a 202 always has its event (policy ReceiptRelay, service ADR 0005). This context does not apply the receipt to the shipment: seller-inbound owns that.

New read models: InboundShipmentView (from InboundShipmentLabelled, InboundShipmentShipped, InboundShipmentReceived; the poll returns only SHIPPED shipments of the vendor's nodes) and CatalogPackagingView (from CatalogItemPackagingDeclared, CatalogItemPackLevelRetired), exposed on the listing payload as packaging[].

Return advices and outcomes​

Built, ADR 0012 as realized by vendor-connectivity ADR 0014 (return advices and return outcomes).

Submission gains the kind RETURN_OUTCOME and the command SubmitReturnOutcome (REST POST /vendor/return-outcomes, 202 and a transactionId, like every vendor write). A RETURN_OUTCOME names an AUTHORIZED advice of ReturnAdviceView and the advice's node, which belongs to the submitting vendor: an unknown vendor, authorization or node is ErrNotFound (404 not-found), a node of another vendor ErrNodeNotOwnedByVendor, a nodeId that is not the advice's node ErrValidation (422), and an advice whose outcome is recorded or whose authorization was cancelled ErrIllegalTransition (409). New event VendorReturnOutcomeSubmitted, appended in the same unit of work that saves the submission and moves the advice to OUTCOME_RECORDED; its consumer is customer-returns.

New read model: ReturnAdviceView (from customer-returns ReturnAuthorized, ReturnLabelIssued, ReturnCancelled), with states AUTHORIZED, CANCELLED and OUTCOME_RECORDED; the poll (GET /vendor/return-advices) returns only AUTHORIZED advices of the vendor's nodes.