Skip to main content

Aggregate design canvas

Following the ddd-crew Aggregate Design Canvas v1.1.

This context has no aggregate, by decision (ADR 0002): no command arrives, no state machine decides anything, no invariant is enforced against a caller, and a wrong projection is rebuilt, not corrected. The canvas is therefore applied to the two projections that carry the context's rules, so a reader can see what a fold may and may not do. The "commands" column is empty; the "events" column lists consumed facts.

Source: internal/domain/productview/, internal/domain/categoryview/, internal/application/usecases/consume*.go.

ProductView (one row per catalogue item)​

SectionContent
NameProductView (productview.View), keyed by catalogItemId
DescriptionThe row one product page or search hit renders from. A plain value that facts are folded into; there is no aggregate root and no constructor that enforces a lifecycle
State transitionsItem: stub (empty) to ACTIVE (on CatalogItemCreated) to DISCONTINUED (on CatalogItemDiscontinued, absorbing; a discontinue recorded on a stub is not revived by a late create). Content: none to PUBLISHED to RETIRED, back to PUBLISHED by a higher revision. Price: none to ACTIVE to WITHDRAWN, back to ACTIVE by a higher version. Listing: LIVE and SUPPRESSED, set by state facts
Commands handledNone. Facts are folded by usecases.Consumer and Rebuilder
Events consumedCatalogItemCreated, CatalogItemDiscontinued, ListingCreated, ListingAvailabilityChanged, ListingSuppressed, ListingRestored, ProductContentPublished, ProductContentRetired, ItemPriceChanged, ItemPriceWithdrawn
Events publishedNone
InvariantsHold of the row, not rules against a caller: inStock and purchasable are always recomputed from the row; a listing quantity is never negative; a listing keeps its first item (ListingItemMap); listings are ordered by id; ids are 1 to 64 characters of the opaque-id alphabet; the title is 1 to 500 characters and immutable once set
Guards (idempotence and order)listing asOf, content revision, price version: a fact applies only when strictly newer, otherwise the fold answers Stale and nothing is saved. Inbox on the CloudEvents id
Corrective policiesA fact for an unknown item creates an invisible stub (productview.Stub, the model's StubOnUnknownItem); a state fact for an unknown listing is skipped; a snapshot never rewinds a known listing state (ADR 0002 A16)
Size and boundaryOne row per item with its listings, bullets, attributes and media as JSONB. Facts of one item are serialised by a transaction-scoped advisory lock (GetForUpdate), because three consumer groups write concurrently
ThroughputReads and folds scale with the number of items; N>1 pods is supported by the lock and the guards but is not load-tested
Derived stateinStock, purchasable, searchable, has_price and the weighted tsvector are stored with the row so search can filter and sort on them

CategoryView (the one published tree)​

SectionContent
NameCategoryView (categoryview.View), a singleton row
DescriptionOne published version of the whole category tree. Purchasable counts are not stored: they are derived from ProductView and rolled up the tree at query time
State transitionsVersion 0 (nothing published) to version N to a strictly higher version; a version that is not higher is ignored
Commands handledNone
Events consumedCategoryTreePublished
Events publishedNone
InvariantsIds valid and unique, names non-empty, every parent present, no parent cycle, version at least 1; an invalid tree is an invalid fact (dead-lettered), never half-applied
Guardstree version strictly higher than the current one; the replacement runs under a row lock (CurrentForUpdate)
Size and boundaryThe whole tree in one JSONB value; products keep only a categoryId, so a rename or move re-indexes nothing and shows at once on every path

Why no aggregate​

  • There is no command to validate: every state change is a producer's fact, taken as published (Conformist).
  • A fold never rejects a well-formed fact; the worst case is Stale. The only rejection is an invalid fact, which is a producer bug and goes to the dead-letter topic.
  • Consistency between sources is not enforced here, it is displayed: a row with content but no item master is invisible, a row with no price is shown without one.

Domain events of the aggregate pattern do not exist; the consumed facts are listed on Domain events, the fold rules on Use cases and the types on the Class diagram.