Retail network · Generic domain · EventStorming board

customer-ordering

Takes a shopper's order at checkout with a confirmed delivery promise for every shipment group, and follows each group until it is delivered, lost, returned or cancelled.

GitHub ↗ · Documentation ↗ · Architecture check · Briefings

events published
3
commands
18
policies
27
read models
4
hot spots
5

The story in 2 key events

The pivotal events: the few that matter most, in the order they happen.

  1. Pivotal eventCustomerOrderPlaced
  2. Pivotal eventCustomerOrderCancelled

Listens to (3): contexts whose events this one reacts to

Tells (3): contexts that react to its events

The board, row by row

18 rows, in the order the business story happens: the main path first, then how this context reacts to the others, then the clock. Rows are small stories; read each one left to right.

  • Event
  • Command
  • Actor
  • Aggregate
  • Policy
  • Read model
  • External system
  • Hot spot
  • Opportunity
  1. Register a shopper

    A shopper is registered with an e-mail, which can be used only once, and may start with saved delivery addresses. This is a test shopper, with no real account behind it.

    ActorShopper
    CommandRegisterShopperPOST /shoppers
    AggregateShopper

    Source: application/usecases/shopper.go · domain/shopper/shopper.go

  2. Save a delivery address

    A shopper saves an address to reuse at checkout, up to twenty. At checkout the address is copied into the order, so later edits never change a placed order.

    ActorShopper
    CommandAddSavedAddressPOST /shoppers/{shopperId}/addresses
    AggregateShopper

    Source: application/usecases/shopper.go · domain/shopper/shopper.go

  3. Place an order

    Checkout makes and confirms a delivery promise for each shipment group, and only then stores the order. If an offer is stale, nothing is placed and fresh offers come back. Nothing is placed if delivery-promise is down.

    ActorShopper
    Read modelSaved addresses of the shopper
    CommandPlaceOrderPOST /checkout
    AggregateCustomerOrder
    EventCustomerOrderPlaced
    Systemorder-sourcing
    PolicyQueues one assignment for each shipment group
    Systemdelivery-promise
    PolicyConfirms any promise still provisional

    Source: application/usecases/checkout.go · domain/customerorder/place.go · adapters/outbound/deliverypromise/gateway.go

  4. Release holds a failed checkout left behind

    If a later group fails to confirm, the promises already confirmed are cancelled. A cancel that itself fails is queued and retried until delivery-promise lets the capacity go.

    TimeCompensation worker
    PolicyEvery pass, retry the promise cancels a failed checkout could not perform
    Read modelQueue of failed cancels
    CommandCancelPromisea background job
    Systemdelivery-promise
    PolicyCancels the confirmed promise and returns its capacity

    Source: adapters/outbound/compensation/worker.go · application/compensation/compensation.go · application/usecases/checkout.go

  5. Ask to cancel an order

    The shopper asks to cancel every group not yet locked. It is a request: the group waits until order-sourcing answers, and a vendor that ships first wins.

    ActorShopper
    CommandCancelOrderPOST /orders/{orderId}/cancellations
    AggregateCustomerOrder
    EventCustomerOrderCancelled
    Systemorder-sourcing
    PolicyCancels each group not yet locked, or refuses it
    Systemdelivery-promise
    PolicyCancels the promises of the cancelled groups

    Source: application/usecases/cancel.go · domain/customerorder/cancel.go

  6. Cancel a group whose promise cannot be kept

    When delivery-promise finds no route that can still deliver, the group is cancelled at once rather than left open.

    Systemdelivery-promise
    EventPromiseUnkeepable
    PolicyWhenever a promise is unkeepable, cancel its shipment group
    CommandCancelUnkeepableGroupstarted by the policy
    AggregateCustomerOrder
    EventCustomerOrderCancelled
    Systemorder-sourcing
    PolicyCancels the group's assignment, or refuses it if already locked
    Systemdelivery-promise
    PolicyCancels the group's promise

    Source: application/usecases/consume_promise.go · domain/customerorder/cancel.go

  7. Accept a cancellation

    order-sourcing confirms it cancelled the group. The group, and the order if nothing else remains, becomes Cancelled.

    Systemorder-sourcing
    EventFulfillmentCancelled
    PolicyWhenever order-sourcing cancels a group, mark the group cancelled
    CommandConfirmGroupCancelledstarted by the policy
    AggregateCustomerOrder

    Source: application/usecases/consume_sourcing.go · domain/customerorder/cancel.go

  8. Accept a refusal to cancel

    If the group was already locked, order-sourcing refuses. The group goes back to Locked and the vendor ships.

    Systemorder-sourcing
    EventFulfillmentCancelRefused
    PolicyWhenever order-sourcing refuses a cancel, put the group back to locked
    CommandRefuseGroupCancellationstarted by the policy
    AggregateCustomerOrder

    Source: application/usecases/consume_sourcing.go · domain/customerorder/cancel.go

  9. Follow a revised promise

    When delivery-promise moves a promise to a later window, the group's delivery window, ship-by and node move with it. A revision no newer than the stored one changes nothing. A later delivery date also decides a delay notice.

    Systemdelivery-promise
    EventPromiseRevised
    PolicyWhenever a promise is revised, move the group's window to the new one
    CommandUpdateGroupPromisestarted by the policy
    AggregateCustomerOrder
    EventShopperNoticeDecided
    System · outsideStorefront
    PolicyTells the shopper when the notice policy names the marketplace or the seller

    Source: application/usecases/consume_promise.go · domain/customerorder/commands.go

  10. Record the promise verdict

    The tracking view shows whether the promise was kept or broken, and by how many minutes. An at-risk promise shows its reason the same way.

    Systemdelivery-promise
    EventPromiseBroken
    PolicyWhenever a promise is kept or broken, record the verdict on the group
    CommandApplyPromiseBrokenstarted by the policy
    Read model · kept up to dateTracking view

    Source: application/usecases/consume_promise.go · adapters/inbound/kafka/handlers.go

  11. Mark a group in fulfilment

    order-sourcing locks the group to a node. The group moves from Promised to Locked and the assignment is linked to it.

    Systemorder-sourcing
    EventFulfillmentLocked
    PolicyWhenever a group is locked at a node, mark it in fulfilment
    CommandMarkInFulfillmentstarted by the policy
    AggregateCustomerOrder
    Read model · kept up to dateAssignment links

    Source: application/usecases/consume_sourcing.go · domain/customerorder/commands.go

  12. Mark a group shipped

    order-sourcing reports the packages. The group becomes Shipped, and deliveries that arrived early are replayed so the group can close at once. The shopper notice for shipped is decided too.

    Systemorder-sourcing
    EventFulfillmentShipped
    PolicyWhenever a group ships, mark it shipped and replay early deliveries
    CommandMarkGroupShippedstarted by the policy
    AggregateCustomerOrder
    EventShopperNoticeDecided
    Read model · kept up to dateTracking view
    System · outsideStorefront
    PolicyTells the shopper when the notice policy names the marketplace or the seller

    Source: application/usecases/consume_sourcing.go · domain/customerorder/commands.go

  13. Close a group on delivery

    A package is delivered. A group is Delivered once every package it announced is delivered. A package shared by merged groups closes all of them. The shopper notice for delivered is decided too.

    Systemshipping-and-tracking
    EventPackageDelivered
    PolicyWhenever a package is delivered, mark it for every group that names it
    CommandMarkGroupDeliveredstarted by the policy
    AggregateCustomerOrder
    EventShopperNoticeDecided
    Read model · kept up to dateTracking view
    System · outsideStorefront
    PolicyTells the shopper when the notice policy names the marketplace or the seller

    Source: application/usecases/consume_tracking.go · domain/customerorder/commands.go

  14. Mark a group lost or returned

    One lost package loses the group, and one returned package returns it. Both are final. The shopper notice for lost or returned is decided too.

    PolicyWhenever a package is lost or returned, mark its group lost or returned
    CommandMarkGroupLoststarted by the policy
    AggregateCustomerOrder
    EventShopperNoticeDecided
    Read model · kept up to dateTracking view
    System · outsideStorefront
    PolicyTells the shopper when the notice policy names the marketplace or the seller

    Source: application/usecases/consume_tracking.go · domain/customerorder/commands.go

  15. Show the delivery window of the day

    The carrier narrows a package to a time window on the day. It shows on the tracking view only; the promise and the order are untouched. A notice for the shopper is decided too, by the same policy.

    Systemshipping-and-tracking
    EventPackageEtaWindowAssigned
    PolicyWhenever a package gets a day-of window, show it unless a newer one is stored
    CommandApplyPackageEtastarted by the policy
    AggregatePolicy
    EventShopperNoticeDecided
    Read model · kept up to dateTracking view
    System · outsideStorefront
    PolicyTells the shopper when the notice policy names the marketplace or the seller

    Source: application/usecases/consume_eta.go · application/usecases/notice.go · 0017-notification-policy-and-shopper-notice-decided.md

  16. Warn about a delivery point that keeps failing

    The carrier flags a drop-off point after repeated failures. The warning shows on the tracking view and a notice for the shopper is decided; the promise and the order are untouched.

    Systemshipping-and-tracking
    EventPackageDeliveryPointFlagged
    PolicyWhenever a delivery point is flagged, show the warning and decide who tells the shopper
    CommandApplyDeliveryPointFlagstarted by the policy
    AggregatePolicy
    EventShopperNoticeDecided
    Read model · kept up to dateTracking view
    System · outsideStorefront
    PolicyTells the shopper when the notice policy names the marketplace or the seller

    Source: application/usecases/consume_point_flag.go · application/usecases/notice.go · 0015-delivery-point-advisory-on-the-tracking-view.md

  17. Show that a pickup package is waiting

    A package sent to a pickup point reaches it. The tracking view shows where it waits and until when. The order keeps moving on the shipment events and nothing else changes.

    Systemshipping-and-tracking
    EventPackageReadyForCollection
    PolicyWhenever a pickup package reaches its point, show where it waits and until when
    CommandApplyPackageReadyForCollectionstarted by the policy
    Read model · kept up to dateTracking view

    Source: application/usecases/consume_pickup.go · 0016-checkout-to-a-pickup-point.md

  18. Show that a pickup package was collected

    The shopper collects the package at the pickup point. The tracking view shows the collection and its proof code. Like the deposit, it changes no order.

    Systemshipping-and-tracking
    EventPackageCollected
    PolicyWhenever a pickup package is collected, show the collection with its proof code
    CommandApplyPackageCollectedstarted by the policy
    Read model · kept up to dateTracking view

    Source: application/usecases/consume_pickup.go · 0016-checkout-to-a-pickup-point.md

Hot spots and opportunities

Open questions and known gaps, each taken from a decision record or a document in the repository, never invented. Opportunities are improvements the documentation already names.

  • Hot spotIf delivery-promise is slow or down, checkout answers 503. There is no fallback promise, so the shopper must retry.

    Source: docs/ddd/eventstorming.md

  • Hot spotThe cancel check is advisory. A lock this context has not yet consumed is invisible, so order-sourcing's answer decides.

    Source: docs/ddd/eventstorming.md

  • Hot spotA delivery can arrive before the shipment it belongs to. It is stored and replayed later; an unknown order is skipped, not retried.

    Source: docs/ddd/eventstorming.md

  • Hot spotA shopper whose consolidated offer expired is re-quoted without that tier. This is an accepted limitation.

    Source: adr/0013-consolidated-tier-and-chosen-delivery-day.md

  • Hot spotThe ship-to route is called restricted, but the fleet has no authentication and none is planned here.

    Source: docs/ddd/bounded-context-canvas.md

Opportunities

This board is a reconstruction from the code and documentation of customer-ordering at origin/develop, not a workshop output. Roles are the ones the documentation names. How the boards were made.