Skip to main content

Aggregate Design Canvas

Following the ddd-crew Aggregate Design Canvas v1.1. Three aggregate roots: VendorAccount, PurchaseOrder and Submission. The Go packages are internal/domain/vendor, internal/domain/purchaseorder and internal/domain/submission; the Postgres tables are vendor_accounts, purchase_orders and submissions.

VendorAccount​

1. Name​

VendorAccount (vendor.Account), identified by vendorId.

2. Description​

A vendor organisation, its standing and its ack window. The ack window feeds every purchase order's ackBy. The nodes a vendor may operate come from the VendorNodeView read model (vendor_nodes, fed by node-topology), not from a collection inside the aggregate. The rate limit is not part of the account: it is one process-wide bucket (RATE_LIMIT_RPS).

3. State Transitions​

Source: internal/domain/vendor/vendor.go (Onboard, Suspend, Reinstate) and internal/application/usecases/vendors.go.

Omitted: nothing. There is no terminal state and no delete; suspending a suspended vendor, or reinstating an active one, is a no-op that raises no event.

4. Enforced Invariants​

InvariantEnforced by
ackWindow is between 1h and 24h (60 to 1440 minutes, also a database check)ErrAckWindowOutOfRange
A vendor acts only on its own nodes and ordersErrNodeNotOwnedByVendor (checked against VendorNodeView for node-scoped calls and against the order's vendorId for PO-scoped calls)
A suspended vendor's writes are refused; its reads are notErrVendorSuspended (requireActive before every vendor write)

5. Corrective Policies​

None. The only coupling is the guard above: a SUSPENDED vendor's writes answer 409 vendor-suspended, its reads (polls, transaction status, scorecard) still work, and purchase orders already issued stay as they are.

6. Handled Commands​

CommandIssued byChannel
OnboardVendorNetwork partner managerREST POST /vendors
SuspendVendoroperatorREST POST /vendors/{vendorId}/suspensions (optional reason)
ReinstateVendoroperatorREST POST /vendors/{vendorId}/reinstatements

7. Created Events​

EventRaised whenFull CloudEvents type
VendorOnboardedOnboardVendor creates the accountcom.retailnetwork.partner.vendor-connectivity.vendoraccount.VendorOnboarded
VendorSuspendedSuspendVendor on an ACTIVE accountcom.retailnetwork.partner.vendor-connectivity.vendoraccount.VendorSuspended
VendorReinstatedReinstateVendor on a SUSPENDED accountcom.retailnetwork.partner.vendor-connectivity.vendoraccount.VendorReinstated

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 (purchaseorder.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: Line{LineNo, ListingID, Quantity}, Ack{Decision (Accept or Reject), ReasonCode}, Label{PackageNo, LabelRef, TrackingNumber, Carrier}, Shipment{TrackingNumbers, ShippedAt} and RejectReason (OUT_OF_STOCK, UNKNOWN_LISTING, CANNOT_MEET_SHIP_BY, DISCONTINUED).

3. State Transitions​

Source: internal/domain/purchaseorder/purchaseorder.go, commands.go, commands_ack.go, commands_shipment.go (the State constants and the transitions) and internal/application/usecases/orders.go, submissions.go.

Omitted: RequestLabel, which changes no state (it adds Labels to an ACCEPTED order). The qualifiers after ProcessSubmission (outcome and decision) say which of the three ACK_PROCESSING transitions applies (ApplyAckOutcome).

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 ISSUED (an EXPIRED or CANCELLED order is an illegal transition)ErrCancelAfterAcknowledgement
Tracking numbers on a shipment confirmation equal the order's labelled onesErrConfirmWithoutLabel
ackBy = min(issuedAt + ackWindow, requiredShipBy - handlingTime), fixed at issuecomputed by purchaseorder.Issue (ComputeAckBy); a business decision, no Err...

5. Corrective Policies​

PolicyRuleEffect 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 the assignment's latest releaseCancel; past ISSUED it is logged and left alone
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, from the aggregator model)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, from the aggregator model)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 CancelOnSourcingCancelKafka FulfillmentCancelled
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 row carries a version for optimistic concurrency (ErrConcurrentUpdate, re-run once by the use case).

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, inbound receipt, return outcome) and its processing outcome. Value objects: Kind (ACKNOWLEDGEMENT, INVENTORY, NODE_REGISTRATION, NODE_PROFILE, SHIPMENT_CONFIRMATION, INBOUND_RECEIPT, RETURN_OUTCOME) and Error{Code, Message, Path}. It is what GET /vendor/transactions/{transactionId} returns.

3. State Transitions​

Source: internal/domain/submission/submission.go (Receive, Complete) and internal/application/usecases/submissions.go.

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, up to 5 passes (DefaultSubmissionMaxAttempts), after which it ends in FAILURE with ErrUpstreamUnavailable.
  • A downstream refusal the callee releases under its Idempotency-Key (replay class RETRYABLE, ADR 0016) keeps the submission PROCESSING like an outage (RecordRefusal counts the attempt and keeps the last refusal); within the same 5 passes it either succeeds or ends in FAILURE with that refusal's own Err... code.

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, POST /vendor/inbound-receipts
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, the vendor's body verbatim (at most 4 MiB), the order or node it concerns and zero or more errors (at most 50). One event in its life.

Read models​

Read modelSource eventsUsed forWhy it is not an aggregate
VendorNodeView (vendor_nodes)node-topology NodeRegistered, NodeOperationalProfileDeclared, 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
ListingView (listings)offer-availability ListingCreatedRefusing an inventory line whose listing belongs to another node, and resolving a PO line's catalogue item for packaging[]offer-availability owns the listing; this context only looks it up

Inbound receipts​

Built: ADR 0005 of this repository realises the aggregator's seller-inbound design (inbound shipments, inbound receipts and catalogue packaging).

Submission has the sixth 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: an unknown vendor, shipment or node is ErrNotFound (404 not-found), ErrNodeNotOwnedByVendor applies to the node, and a receipt that disagrees with the shipment (wrong destination node, a carton not on the manifest unless it is UNEXPECTED, an item not in the carton) is validation-failed, while a shipment that has not shipped is illegal-transition (Shipment.CheckReceipt). New event InboundReceiptSubmitted, appended to the outbox in the same unit of work that accepts the submission, so a 202 always has its event (ADR 0005). This context does not apply the receipt to the shipment: seller-inbound owns that.

Further read models: InboundShipmentView (inbound_shipments) (from InboundShipmentLabelled, InboundShipmentShipped, InboundShipmentReceived; the poll returns only SHIPPED shipments of the vendor's nodes) and CatalogPackagingView (catalog_packaging, from CatalogItemPackagingDeclared, CatalogItemPackLevelRetired), exposed on each purchase order line as packaging[].