Skip to main content

Domain events

The events as design artifacts: one block per event, the business meaning next to the wire facts. The contract and the envelope, with the golden example and the delivery semantics, are on Event catalogue; the decision is ADR 0004. Producing sources: internal/domain/cart/events.go (the four event structs) and internal/adapters/outbound/kafka/encoder.go (type, topic, key, payload). Consuming sources: internal/adapters/inbound/kafka/handlers.go, handlers_pricing.go and internal/application/usecases/consume.go.

Envelope in one table​

AttributeValue for this context
specversion1.0, structured JSON mode
idminted once when the event is encoded into the outbox row; a redelivery carries the same id
source/retailnetwork/shopping-cart
typecom.retailnetwork.storefront.shopping-cart.cart.<EventName>
subjectcartId
timethe instant of the change, UTC
datacontenttypeapplication/json
dataschemaurn:retailnetwork:shopping-cart:analytics:<EventName>:v1
Kafka topicretailnetwork.shopping-cart.analytics, for all four events
Kafka keycartId, so one cart's events stay on one partition, in order

Published​

Every event is appended to outbox_events in the same transaction as the cart save (Deps.persist) and published by the relay, at-least-once. All four are analytics-only: no storefront or network context subscribes to a cart fact (Context map). Only these four commands raise events: removal, quantity change, destination, selection, merge, requote and creation raise nothing, by design.

CartLineAdded​

ItemValue
Full typecom.retailnetwork.storefront.shopping-cart.cart.CartLineAdded
Topic / keyretailnetwork.shopping-cart.analytics / cartId
Dataschemaurn:retailnetwork:shopping-cart:analytics:CartLineAdded:v1
Raised byAddLine; adding an item already in the cart merges quantities and the event carries the merged line
Consumersanalytics only
FieldTypeMeaning
cartIdstringThe cart the line was added to.
catalogItemIdstringThe item added.
quantityintegerThe line's quantity after the merge (1 to 99).
attimestampWhen the add happened.

CartDeliveryQuoted​

ItemValue
Full typecom.retailnetwork.storefront.shopping-cart.cart.CartDeliveryQuoted
Topic / keyretailnetwork.shopping-cart.analytics / cartId
Dataschemaurn:retailnetwork:shopping-cart:analytics:CartDeliveryQuoted:v1
Raised byQuoteDelivery, after delivery-promise answered and the quote was stored
Consumersanalytics only
FieldTypeMeaning
cartIdstringThe cart quoted.
destinationPostalPrefixstringThe prefix the quote was computed for.
groupCountintegerHow many shipment groups the quote holds.
attimestampWhen the quote was taken.

CartAbandoned​

ItemValue
Full typecom.retailnetwork.storefront.shopping-cart.cart.CartAbandoned
Topic / keyretailnetwork.shopping-cart.analytics / cartId
Dataschemaurn:retailnetwork:shopping-cart:analytics:CartAbandoned:v1
Raised bythe AbandonInactive sweep: an OPEN cart with no change for 30 days
Consumersanalytics only
FieldTypeMeaning
cartIdstringThe cart abandoned.
lastChangedAttimestampThe cart's last change, the fact the 30-day rule fired on.

CartCheckedOut​

ItemValue
Full typecom.retailnetwork.storefront.shopping-cart.cart.CartCheckedOut
Topic / keyretailnetwork.shopping-cart.analytics / cartId
Dataschemaurn:retailnetwork:shopping-cart:analytics:CartCheckedOut:v1
Raised bythe policy CloseOnCheckoutCompleted, on checkout's CheckoutCompleted
Consumersanalytics only
FieldTypeMeaning
cartIdstringThe cart closed.
checkoutSessionIdstringThe session whose completion closed it.
attimestampWhen the cart was closed.

A complete example envelope (CartLineAdded, the encoder's golden file) is on Event catalogue.

Consumed​

Every consumer applies an event once: the CloudEvents id is claimed in processed_events in the same transaction as the effect, and a duplicate is acknowledged without effect. Consumers dispatch on the full type string. The group ids come from mandatory variables (OFFER_AVAILABILITY_CONSUMER_GROUP, PRICING_CONSUMER_GROUP, CHECKOUT_CONSUMER_GROUP); the service refuses to start without them. A payload that can never be applied is dead-lettered to <topic>.dlq.

From offer-availability (retailnetwork.offer-availability.events, Conformist)​

EventFull typeFields usedWhat this context does
CatalogItemCreatedcom.retailnetwork.commerce.offer-availability.catalogitem.CatalogItemCreatedcatalogItemIdMarks the item catalogued in PurchasabilityView (rm_items).
CatalogItemDiscontinuedcom.retailnetwork.commerce.offer-availability.catalogitem.CatalogItemDiscontinuedcatalogItemIdMarks the item discontinued, terminally: it can no longer be added; lines already in carts stay and checkout's quote refuses them.

From pricing (retailnetwork.pricing.events, Customer/Supplier, we are the Customer)​

EventFull typeFields usedWhat this context does
ItemPriceChangedcom.retailnetwork.storefront.pricing.itemprice.ItemPriceChangedcatalogItemId, currency, effectivePriceMinor, versionRecords the effective price when version is newer; feeds purchasability and the estimate.
ItemPriceWithdrawncom.retailnetwork.storefront.pricing.itemprice.ItemPriceWithdrawncatalogItemId, versionClears the price when version is newer; an unpriced item is not purchasable.
DeliveryChargeScheduleChangedcom.retailnetwork.storefront.pricing.deliverychargeschedule.DeliveryChargeScheduleChangedversion, tiers[{tier, chargeMinor, freeOverMinor?}]Replaces the current schedule when version is higher.
TaxTableChangedcom.retailnetwork.storefront.pricing.taxtable.TaxTableChangedversion, bands[{postalPrefixFrom, postalPrefixTo, rateBasisPoints}]Replaces the current tax table when version is higher.

From checkout (retailnetwork.checkout.events, Customer/Supplier, we are the Customer)​

EventFull typeFields usedWhat this context does
CheckoutCompletedcom.retailnetwork.storefront.checkout.checkoutsession.CheckoutCompletedcartId, sessionIdOPEN -> CHECKED_OUT and CartCheckedOut is raised. An unknown cart, or one that is not OPEN, is acknowledged and logged at WARN.

Idempotency and ordering​

  • Inbox. One row in processed_events per consumed id, in the effect's transaction, so redelivery is a no-op.
  • Versions. Price, schedule and tax events are guarded by their version: reordered or replayed events cannot move a view backwards.
  • Published ordering. Per cart, because the key is the cart id. Across carts there is none.
  • No cross-key ordering on input. A price or a discontinuation can arrive before the item's CatalogItemCreated; the view then holds a stub row (catalogued false) that is not purchasable until the creation arrives.
  • Evolution. A breaking payload change is a new .v2 type; consumers ignore unknown types and unknown fields.