Skip to main content

Aggregate Design Canvas

Built on develop, not deployed

Derived from model/model.yaml. The pricing service is built on develop (IQVO/pricing at 5a18326, checked 2026-10-27) and not deployed (no warehouse-infra entry). Every Err... name, REST route and CloudEvents type of this context named on this page exists in the service; where the built service differs from the model's design, the page says so (As built) or the context's Service and operations section lists it.

Following the ddd-crew Aggregate Design Canvas v1.1. The model has four aggregate roots in this context, ItemPrice, DeliveryChargeSchedule, TaxTable and PriceQuote, and one read model, CatalogItemView. Go packages as built: internal/domain/itemprice, internal/domain/quote, internal/domain/schedule, internal/domain/tax (plus shared).

ItemPrice​

1. Name​

ItemPrice (itemprice.ItemPrice), identified by catalogItemId.

2. Description​

List price and sale windows of one catalogue item, versioned. The effective price is the lowest active sale price, else the list price. Value objects:

Value objectFieldsNote
MoneyamountMinor, currencyInteger minor units of the one configured currency.
SaleWindowsaleId, price, from, toA time-bounded sale price; windows of one item never overlap.

3. State Transitions​

Derived from: model.yaml → contexts[pricing].aggregates[ItemPrice].states, .transitions, .commands, .policies.

The entry arrow [*] --> ACTIVE is the creating command SetListPrice; the model lists transitions between states only, so the creation and the self-transition for sale management are this page's reading. The model names no transition out of WITHDRAWN: a withdrawn price is final (ADR 0002 A3), accepts no list-price change, sale or second withdraw (409 illegal-transition) and is never revived; selling the item again needs a new catalogue item.

4. Enforced Invariants​

InvariantEnforced by
Every amount is non-negativeall commands → ErrNegativeAmount
All prices of an item use the configured currencyall commands → ErrCurrencyMismatch
A sale price is below the list priceScheduleSale → ErrSaleNotBelowList
Sale windows of one item never overlapScheduleSale → ErrOverlappingSaleWindow (409 overlapping-sale-window)
The item exists in the local CatalogItemView and is not DISCONTINUEDSetListPrice, ScheduleSale → ErrUnknownCatalogItem
A WITHDRAWN price is final: no list-price change, sale, cancellation or second withdrawall commands → illegal-transition (409)
An item holds at most 50 live sale windows; a window ends after it starts and in the future; every amount is at most MaxMinor (1,000,000,000 minor units)ScheduleSale, SetListPrice → validation-failed (422)

Derived from: model.yaml → contexts[pricing].aggregates[ItemPrice].invariants.

5. Corrective Policies​

PolicyOwnerRuleEffect on this aggregate
PublishEffectivePriceOnWindowBoundarythis contextEmit ItemPriceChanged when a sale starts or ends, idempotent per item and boundary.No state change; republishes the effective price as the windows dictate.
WithdrawOnDiscontinuethis contextOn CatalogItemDiscontinued withdraw the item's price.ACTIVE → WITHDRAWN, ItemPriceWithdrawn.
Idempotent consumptionthis contextEvery consumed event is applied once (inbox on the CloudEvents id).A repeated CatalogItemDiscontinued is acknowledged without effect.

6. Handled Commands​

CommandTriggerTransition
SetListPriceMerchandiser, REST POST /item-prices / PUT /item-prices/{catalogItemId}/list-price[*] → ACTIVE, then list-price updates in ACTIVE
ScheduleSaleMerchandiser, REST POST /item-prices/{catalogItemId}/salesnone (adds a window)
CancelSaleMerchandiser, REST POST /item-prices/{catalogItemId}/sales/{saleId}/cancellationsnone (removes a window); raises ItemPriceChanged when the effective price reverts
WithdrawPriceMerchandiser, REST POST /item-prices/{catalogItemId}/withdrawals, or WithdrawOnDiscontinue on Kafka CatalogItemDiscontinuedACTIVE → WITHDRAWN

7. Created Events​

EventRaised whenFull CloudEvents type
ItemPriceChangedSetListPrice, ScheduleSale, CancelSale are saved, and on a sale window boundary (PublishEffectivePriceOnWindowBoundary)com.retailnetwork.storefront.pricing.itemprice.ItemPriceChanged
ItemPriceWithdrawnWithdrawPrice is savedcom.retailnetwork.storefront.pricing.itemprice.ItemPriceWithdrawn

CancelSale raises ItemPriceChanged (the effective price reverts to the list price) and has no event of its own, by decision: a cancelled sale changes the effective price, the window-boundary policy already emits that as ItemPriceChanged (idempotent per item and boundary), and a separate event would duplicate the fact. Both events leave through the transactional outbox in the same transaction as the save.

8. Throughput​

Estimate. The model says "low: merchandising writes; bursts on sale boundaries". One row per catalogue item, so contention on a single catalogItemId is negligible; the burst is the boundary scheduler republishing many items at once when a large sale starts or ends.

9. Size​

Estimate. The model says "one row per ACTIVE catalogue item; ~10^6". A root row with the list price, a handful of sale windows, and the version every event carries.

DeliveryChargeSchedule​

1. Name​

DeliveryChargeSchedule (schedule.DeliveryChargeSchedule), identified by scheduleId.

2. Description​

The delivery charge per service tier (SAME_DAY, NEXT_DAY, TWO_DAY, STANDARD), with an optional free-over threshold per tier. Exactly one schedule is current; versions strictly increase.

Value objectFieldsNote
TierChargetier, charge, freeOver?charge is a Money; freeOver is the optional free-delivery threshold.

3. State Transitions​

Derived from: model.yaml → contexts[pricing].aggregates[DeliveryChargeSchedule].states, .transitions, .notes.

Publishing a new schedule creates it CURRENT and moves the previous current one to SUPERSEDED in the same transaction; the read route GET /delivery-charge-schedules/current serves the CURRENT one.

4. Enforced Invariants​

InvariantEnforced by
A schedule names a charge for every tierPublishChargeSchedule → ErrIncompleteChargeSchedule
A new schedule's version strictly increasesPublishChargeSchedule → ErrNonIncreasingVersion

5. Corrective Policies​

None in the model. A wrong schedule is corrected by publishing a higher version, never by editing.

6. Handled Commands​

CommandTriggerTransition
PublishChargeScheduleMerchandiser, REST POST /delivery-charge-schedules[*] → CURRENT; previous CURRENT → SUPERSEDED

7. Created Events​

EventRaised whenFull CloudEvents type
DeliveryChargeScheduleChangedPublishChargeSchedule is savedcom.retailnetwork.storefront.pricing.deliverychargeschedule.DeliveryChargeScheduleChanged

8. Throughput​

Estimate. The model says "rare".

9. Size​

Estimate. The model says "one current + history": one row per published version, plus its four tier rows.

TaxTable​

1. Name​

TaxTable (tax.TaxTable), identified by taxTableId.

2. Description​

A synthetic tax table (D10): basis-point rates by destination postal-prefix band. Exactly one table is current; versions strictly increase.

Value objectFieldsNote
TaxBandpostalPrefixFrom, postalPrefixTo, rateBasisPointsBands never overlap; the rate is within the configured range.

3. State Transitions​

Derived from: model.yaml → contexts[pricing].aggregates[TaxTable].states, .transitions, .notes.

4. Enforced Invariants​

InvariantEnforced by
Bands never overlapPublishTaxTable → ErrOverlappingTaxBand
A rate is within the configured rangePublishTaxTable → ErrRateOutOfRange

5. Corrective Policies​

None in the model; supersede with a higher version.

6. Handled Commands​

CommandTriggerTransition
PublishTaxTableMerchandiser, REST POST /tax-tables[*] → CURRENT; previous CURRENT → SUPERSEDED

7. Created Events​

EventRaised whenFull CloudEvents type
TaxTableChangedPublishTaxTable is savedcom.retailnetwork.storefront.pricing.taxtable.TaxTableChanged

8. Throughput​

Estimate. The model says "rare".

9. Size​

Estimate. The model says "one current + history": one row per version, plus its bands.

PriceQuote​

1. Name​

PriceQuote (quote.PriceQuote), identified by quoteId.

2. Description​

A binding, immutable, expiring price snapshot for one checkout: lines with unit and line totals, groups with tier and delivery charge, tax, total, the versions of price, schedule and tax table used, issuedAt and expiresAt.

Value objectFieldsNote
QuoteLinecatalogItemId, quantity, unitPrice, lineTotalunitPrice is the item's effective price at issue.
QuoteGroupgroupNo, tier, deliveryChargeThe price of the tier the shopper selected for that shipment group.

3. State Transitions​

Derived from: model.yaml → contexts[pricing].aggregates[PriceQuote].states, .transitions, .commands.

4. Enforced Invariants​

InvariantEnforced by
Every line names an ACTIVE priceIssuePriceQuote → ErrItemNotPriced
A quote has at least one lineIssuePriceQuote → ErrEmptyQuote
All amounts use the configured currencyIssuePriceQuote → ErrCurrencyMismatch

5. Corrective Policies​

PolicyOwnerRuleEffect on this aggregate
QuoteTtlthis contextA PriceQuote expires 15 minutes (default) after issue; expiry is by time, immutable otherwise.ISSUED → EXPIRED through ExpireQuote.
ExpireOnQuoteExpirycheckoutAn OPEN or DECLINED session expires with its price quote.None here; quote expiry is checkout-internal TTL state, so checkout keeps its own clock and pricing publishes no expiry event.

6. Handled Commands​

CommandTriggerTransition
IssuePriceQuotecheckout, REST POST /price-quotes[*] → ISSUED
ExpireQuotethe clock (QuoteTtl), a schedulerISSUED → EXPIRED

7. Created Events​

EventRaised whenFull CloudEvents type
PriceQuoteIssuedIssuePriceQuote is savedcom.retailnetwork.storefront.pricing.pricequote.PriceQuoteIssued

PriceQuoteIssued is analytics-only (topic retailnetwork.pricing.analytics). ExpireQuote publishes nothing, by decision (no PriceQuoteExpired exists): expiry is checkout-internal TTL state, not a business fact anyone consumes. It is observable from expiresAt, and checkout enforces it at confirm (ErrPriceQuoteExpired).

8. Throughput​

Estimate. The model says "one per checkout session opened". Reads outnumber writes: checkout reads the quote back at confirm.

9. Size​

Estimate. The model says "TTL minutes; retained for the order's lifetime via the checkout session reference". Lines and groups are a handful per quote; the rows outlive the TTL because the placed order's totals must stay explainable.

Read models​

Read modelSource eventsServesWhy it is not an aggregate
CatalogItemViewoffer-availability CatalogItemCreated, CatalogItemDiscontinuedErrUnknownCatalogItem enforcement inside SetListPrice / ScheduleSaleIt protects no invariant of its own and takes no command; it is a projection of facts offer-availability owns, rebuildable by replaying the topic.

Derived from: model.yaml → contexts[pricing].read_models. The view keeps exactly what the invariant needs: that the item exists and whether it is discontinued. The consumed events carry only catalogItemId in the fields this context declares, so the view stores id and state, not the item's attributes.