Skip to main content

Aggregate Design Canvas

Following the ddd-crew Aggregate Design Canvas v1.1. There are three aggregate roots: CatalogItem, Listing and InventoryFeed; nodestatus.View is a read model. The code is internal/domain/{catalog,listing,feed,nodestatus}; the decision record is ADR 0002. Every aggregate carries a version that counts saves; a save expects the stored version to be one less, and a mismatch is ports.ErrConcurrentUpdate (concurrent-update, 409). Throughput and size are not measured anywhere in the repository, so sections 8 and 9 say what the code does about contention and storage.

CatalogItem​

1. Name​

CatalogItem (Go type catalog.Item, internal/domain/catalog/catalog.go), identified by catalogItemId (minted as item-<uuid>).

2. Description​

The network's own item master entry: title, dimensions in millimetres, weight in grams, handling flags (hazmat, fragile), an optional each-level GTIN and the packaging hierarchy (catalog.PackLevelDef, internal/domain/catalog/packaging.go). It is independent of who ships the item. Vendors refer to it through a listingId, never by their own SKU.

3. State Transitions​

Source: internal/domain/catalog/catalog.go (catalog.Create, catalog.Item.Discontinue).

DISCONTINUED is final. Discontinuing a DISCONTINUED item changes nothing and raises no event. Pack levels have their own flag, active, not a state: a level goes from active to retired and never back.

4. Enforced Invariants​

InvariantEnforced by
Title 1 to MaxTitle characters, trimmed; length, width, height and weight between 1 and MaxDimensioncatalog.Create -> catalog.ErrInvalidItemDimensions, shared.ErrValidation
A GTIN is 8, 12, 13 or 14 digits with a valid mod-10 check digit, stored as 14; indicator digit 9 (variable measure) is refusedcatalog.ParseGTIN -> catalog.ErrInvalidGTIN
A GTIN identifies one item or pack level foreverDeclarePackLevel -> catalog.ErrGtinAlreadyAssigned; across items the CreateCatalogItem pre-check and the unique indexes catalog_items_gtin_key, catalog_item_pack_levels_gtin_key
EACH has exactly one unit per pack and no child; every higher level has unitsPerPack of at least 2, 1 to 1000000catalog.ErrInvalidPackQuantity
A higher level names an active, lower child level of the same item, unitsPerPack is a multiple of the child's and at least twice itcatalog.ErrPackLevelOrder, catalog.ErrInvalidPackQuantity
Dimensions come all three or none; a gross weight is no lighter than the contentscatalog.ErrInvalidPackDimensions
The unitsPerPack and child of an active level never change for its GTIN; a new quantity is a new GTIN at that levelcatalog.ErrPackQuantityImmutable
A discontinued item takes no packaging changeshared.ErrIllegalTransition

5. Corrective Policies​

  • Discontinuing an item suppresses its listings in the same unit of work: usecases.DiscontinueItem calls listing.Listing.Suppress(ReasonDiscontinued) on every listing of the item that allows it (Use cases).
  • A new GTIN at a level that already has an active one retires the old level in the same aggregate version (CatalogItemPackLevelRetired, then CatalogItemPackagingDeclared).
  • Neighbours react to the events: delivery-promise, order-sourcing, pricing, product-content, product-discovery and shopping-cart to CatalogItemDiscontinued, seller-inbound and vendor-connectivity to the pack-level events.

6. Handled Commands​

CommandIssued byInbound adapter
CreateCatalogItemNetwork merchandisingREST POST /catalog-items
DiscontinueItemNetwork merchandisingREST POST /catalog-items/{catalogItemId}/discontinuations
DeclarePackLevelNetwork merchandisingREST PUT /catalog-items/{catalogItemId}/packaging/{level}
RetirePackLevelNetwork merchandisingREST POST /catalog-items/{catalogItemId}/packaging/{level}/retirements

7. Created Events​

EventRaised whenFull CloudEvents type
CatalogItemCreatedCreateCatalogItem commitscom.retailnetwork.commerce.offer-availability.catalogitem.CatalogItemCreated
CatalogItemDiscontinuedDiscontinueItem moves the item to DISCONTINUED...catalogitem.CatalogItemDiscontinued
CatalogItemPackagingDeclareda pack level is declared, or re-declared with new dimensions or weight...catalogitem.CatalogItemPackagingDeclared
CatalogItemPackLevelRetireda level is retired explicitly or replaced by a new GTIN...catalogitem.CatalogItemPackLevelRetired

8. Throughput​

Writes come from merchandising, one item at a time; reads (GET /catalog) dominate. Concurrent writers to one item are resolved by the version check; nothing is measured.

9. Size​

One catalog_items row of scalar fields per item plus one catalog_item_pack_levels row per level ever declared (retired ones are kept). Never purged.

Listing​

1. Name​

Listing (listing.Listing, internal/domain/listing/listing.go), identified by listingId. Natural key (catalogItemId, nodeId, ownerRef).

2. Description​

One catalogue item offered from one node, optionally for one seller's stock (ownerRef, empty = operator-owned), with the node's claimed available quantity, its basis and the feed it came from. It holds one value object, listing.Availability{Qty, Basis, AsOf, FeedID}. Before the first feed it is 0, UNKNOWN, with no asOf.

3. State Transitions​

Source: internal/domain/listing/listing.go (listing.CreateOwned, Suppress, Restore).

A listing starts SUPPRESSED with reason DISCONTINUED when its item is discontinued (this wins) and NODE_NOT_SELLABLE when the node is not ACTIVE in the local node_status_view; it then raises ListingSuppressed right after ListingCreated. It starts SUPPRESSED with OWNER_SUSPENDED when the owner is SUSPENDED in seller_status_view and no higher cause holds (ADR 0013). SUPPRESSED with DISCONTINUED is final: Restore refuses it. The database enforces the pairing of state and reason (listings_state_reason).

4. Enforced Invariants​

InvariantEnforced by
availableQty is at least 0 and at most 2147483647listing.Listing.ApplyAvailability -> listing.ErrNegativeAvailability, shared.ErrValidation; CHECK available_qty >= 0
An update whose asOf is not after the current one is stale and changes nothing (monotonic per listing)ApplyAvailability -> listing.ErrStaleAvailability (inside a feed the line is skipped and counted)
Only a SUPPRESSED listing whose reason is not DISCONTINUED is restored, and only when the node is sellablelisting.Listing.Restore -> shared.ErrIllegalTransition, listing.ErrNodeNotSellable
A LIVE listing can be suppressed; a SUPPRESSED one only for a reason that outranks its current one (OWNER_SUSPENDED < NODE_NOT_SELLABLE < DISCONTINUED); any other repeat is refusedlisting.Listing.Suppress -> shared.ErrIllegalTransition
One listing per (catalogItemId, nodeId, ownerRef); ids and owner well formedusecases.CreateListing -> listing.ErrDuplicateListing; listings_item_node_owner_key
The basis is one of PHYSICAL, THROUGHPUT_CONSTRAINED, UNKNOWN and is kept as declaredlisting.Basis.Valid

5. Corrective Policies​

  • SuppressOnNodeUnavailable (usecases.ApplyNodeEvent): on NodeSuspended or NodeRetired suppress every LIVE listing of the node with NODE_NOT_SELLABLE; on NodeActivated restore those suppressed for that reason. A move that is illegal for a listing is skipped, so a replay is a no-op.
  • Owner status (usecases.ApplySellerEvent, ADR 0013): on SellerSuspended suppress every LIVE listing the seller owns with OWNER_SUSPENDED; on SellerReinstated reconcile the ones suppressed for that reason (listing.Listing.Reconcile): restored, or handed to the remaining cause. usecases.ApplyReceivedStock (ADR 0014) creates the seller's listing for each received item that has none on the node.
  • Full feed zeroing (listing.Listing.ZeroOut, called by feed.InventoryFeed.Apply): a full feed sets availableQty to 0 on every other listing of the node, keeping its basis and stamping the feed's asOf and id. It does not suppress.
  • Neighbours: delivery-promise and order-sourcing fold every listing event into their own views; product-discovery also consumes the listing events, vendor-connectivity ListingCreated and seller-inbound ListingAvailabilityChanged.

6. Handled Commands​

CommandIssued byInbound adapter
CreateListingNetwork merchandisingREST POST /listings
ApplyAvailability, ZeroOutApplyInventoryFeed, once per feed line and once per zeroed listingnone of their own (inside POST /inventory-feeds)
SuppressApplyNodeEvent (policy), DiscontinueItem, and CreateListing when it starts suppressedKafka consumer of retailnetwork.node-topology.events; REST
RestoreApplyNodeEvent (policy)Kafka consumer of retailnetwork.node-topology.events

7. Created Events​

EventRaised whenFull CloudEvents type
ListingCreatedCreateListing commits (carries optional ownerRef)com.retailnetwork.commerce.offer-availability.listing.ListingCreated
ListingAvailabilityChangedavailability changes (not for a stale line, nor when full-feed zeroing meets a listing already at 0)...listing.ListingAvailabilityChanged
ListingSuppresseda listing becomes or starts SUPPRESSED; carries reason...listing.ListingSuppressed
ListingRestoreda listing returns to LIVE...listing.ListingRestored

8. Throughput​

Every feed line is a write on one listing, and a full feed writes many listings of one node at once, in one transaction (SaveMany). The feeds of one node are serialised by the node's node_feed_marks row lock, so two feeds never interleave their writes on the same listings; the version check still backs every save.

9. Size​

One listings row per (item, node, owner) holding the current Availability only; history lives in the events, not on the row. Never purged.

InventoryFeed​

1. Name​

InventoryFeed (feed.InventoryFeed, internal/domain/feed/feed.go), identified by feedId.

2. Description​

One vendor inventory submission for one node, full or partial (fullUpdate), applied atomically. vendor-connectivity owns the Vendor API transaction that carries it; this aggregate records that the feed was received and how it ended. It keeps counters (appliedCount, staleCount, zeroedCount), never the lines.

3. State Transitions​

Source: internal/domain/feed/feed.go (feed.Receive, MarkApplied, MarkSuperseded, MarkFailed, Resubmit).

APPLIED and SUPERSEDED are final: sending the id again is feed.ErrFeedAlreadyApplied. A FAILED feed can be sent again with the same id and the same node; a still-RECEIVED feed cannot (shared.ErrIllegalTransition).

4. Enforced Invariants​

InvariantEnforced by
Valid ids, asOf present, at most 10000 lines, a partial feed has a line, no listing twice, a known basis, quantity within rangefeed.NewSubmission -> shared.ErrValidation (nothing recorded)
Every line names a listing of the feed's nodefeed.InventoryFeed.Apply -> feed.ErrListingNotOnNode (the feed ends FAILED, no line applied)
No line has a negative quantityfeed.InventoryFeed.Apply -> listing.ErrNegativeAvailability (the feed ends FAILED)
A feed whose asOf is strictly before the node's last APPLIED feed changes nothingfeed.Superseded (state SUPERSEDED)
A feed is applied at most oncefeed.ErrFeedAlreadyApplied

5. Corrective Policies​

  • Full feed zeroing: when fullUpdate is true, every listing of the node without a line gets quantity 0 in the same apply (zeroOmitted, in listing id order).
  • Neighbours: node-performance measures feed freshness from InventoryFeedApplied; vendor-connectivity turns the REST answer into its own submission outcome.

6. Handled Commands​

CommandIssued byInbound adapter
ApplyInventoryFeedvendor-connectivityREST POST /inventory-feeds (in-organization)

7. Created Events​

EventRaised whenFull CloudEvents type
InventoryFeedAppliedthe feed reaches APPLIEDcom.retailnetwork.commerce.offer-availability.inventoryfeed.InventoryFeedApplied

A FAILED or SUPERSEDED feed raises no event; the counter availability.inventory_feeds.applied records every outcome (Observability).

8. Throughput​

Medium: one feed per vendor node every few minutes is the design assumption. The node_feed_marks row lock serialises the feeds of one node; feeds of different nodes run in parallel.

9. Size​

One inventory_feeds row per feed (counters only), purged after 30 days (internal/adapters/outbound/postgres/retention.go); one event per applied feed.

Read models​

Read modelSource eventsUsed forWhy it is not an aggregate
nodestatus.View (table node_status_view)node-topology NodeRegistered, NodeActivated, NodeSuspended, NodeRetiredThe sellability of a node when a listing is created; deciding which listings SuppressOnNodeUnavailable acts onIt holds no rule of its own beyond ordering (Observe ignores an older observation and anything after RETIRED); it is a local copy of node-topology's facts and no command of this context changes it.

Packaging hierarchy and owner​

Both came with ADR 0006. CatalogItem gained the optional each-level gtin and the PackLevelDef{Level, GTIN, ChildGTIN, UnitsPerPack, dimensions, GrossWeightG, Active} list with the commands DeclarePackLevel and RetirePackLevel; Listing gained the optional OwnerRef, which widens the uniqueness rule to (catalogItemId, nodeId, ownerRef). Availability is per listing and never summed or moved between owners. This context does not check that an ownerRef names an active seller; it only checks that it is a well-formed id.