Retail network · Core domain · EventStorming board

order-sourcing

Chooses which fulfillment node ships each group of an order, releases it at the right time and tracks it from release to delivery.

GitHub ↗ · Documentation ↗ · Architecture check · Briefings

events published
15
commands
15
policies
35
read models
4
hot spots
5

The board, row by row

16 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. Queue a shipment group

    When an order is placed, each shipment group gets an assignment and the best node is picked; a same-day group is released at once. If no node can serve the group in time, it is marked unsourceable so the promise can be revised.

    Systemcustomer-ordering
    EventCustomerOrderPlaced
    PolicyWhenever an order is placed, queue one assignment per shipment group and pick its best node
    Read modelNetwork graph
    Read modelAvailability copy
    Read modelNode scorecards
    CommandQueueAssignmentstarted by the policy
    AggregateAssignment
    EventFulfillmentQueuedanalytics stream only
    EventFulfillmentUnsourceable
    Systemdelivery-promise
    PolicyFlags the promise as at risk when no node can serve the group
    Systemcustomer-ordering
    PolicyKeeps the reason on the order tracking view

    Source: application/usecases/queue.go · domain/assignment/assignment.go · adapters/inbound/kafka/handlers.go

  2. Release a group to its best node

    A sweep releases every group whose release time has come. The node is re-checked against fresh copies first, and the release records why this node was chosen.

    TimeQueue sweep
    PolicyWhenever a queued group's release time is due, re-check the best node and release the group to it
    Read modelNetwork graph
    Read modelAvailability copy
    Read modelNode scorecards
    CommandReleaseToNodestarted by the clock
    AggregateAssignment
    EventFulfillmentReleasedToNode
    EventFulfillmentSourcingDecidedanalytics stream only
    EventFulfillmentReassigned
    EventFulfillmentUnsourceable
    Systemvendor-connectivity
    PolicyIssues a purchase order to the node
    Systemlinehaul-transportation
    PolicyNotes the planned pickup; nothing is booked yet
    Systemseller-inbound
    PolicyAdds the released lines to its demand view

    Source: application/usecases/release.go · application/usecases/sweep.go · domain/assignment/commands.go

  3. Release one shopper's packages together

    If the shopper chose the consolidated delivery day and a merge limit is published, queued groups with the same key ride on the first group's release. The merge never moves the node.

    TimeQueue sweep
    PolicyWhenever a due consolidated group has queued mates with the same key, release them as one
    CommandReleaseToNodestarted by the clock
    AggregateAssignment
    EventAssignmentsConsolidatedanalytics stream only
    Systemvendor-connectivity
    PolicyReceives one purchase order carrying the lines of every merged group

    Source: application/usecases/release.go · domain/assignment/consolidation.go · 0015-carrier-and-follower-consolidation-at-release.md

  4. Move a queued group to a better node

    A network planner, or the sweep, asks for a fresh search for a group that is still queued. If another node is now better the group moves; if none is left it becomes unsourceable.

    ActorNetwork-ops planner
    Read modelNetwork graph
    Read modelAvailability copy
    CommandReoptimiseAssignmentPOST /assignments/{assignmentId}/reoptimisations
    AggregateAssignment
    EventFulfillmentReassigned
    EventFulfillmentUnsourceable
    Systemlinehaul-transportation
    PolicyUpdates its view of the group's node

    Source: application/usecases/commands.go · domain/assignment/commands.go

  5. Publish a sourcing policy

    A planner sets the cross-region surcharge, how far above the cheapest route the choice may drift to stay in region, and how many groups may merge. Every publish makes the next version; nothing changes until one exists.

    ActorNetwork-ops planner
    CommandPublishSourcingPolicyPUT /sourcing-policy
    AggregatePolicy
    EventSourcingPolicyPublishedanalytics stream only

    Source: application/usecases/policy.go · domain/policy/policy.go · 0014-a-versioned-sourcing-policy.md

  6. Lock the group when the node accepts

    When the node accepts the purchase order, the group is locked on that node and its pickup departure. After that it can no longer be moved or cancelled.

    Systemvendor-connectivity
    EventPurchaseOrderAccepted
    PolicyWhenever the node accepts the purchase order of the pending release, lock the group on that node
    CommandLockAssignmentstarted by the policy
    AggregateAssignment
    EventFulfillmentLocked
    Systemdelivery-promise
    PolicyMoves the capacity hold to the locked node and pickup, then re-judges the promise
    Systemcustomer-ordering
    PolicyMarks the group as in fulfilment
    Systemlinehaul-transportation
    PolicyBooks one package on the pickup departure, or moves it to the next one

    Source: application/usecases/commands.go · domain/assignment/commands_lifecycle.go · adapters/inbound/kafka/handlers_partner.go

  7. Try another node after a refusal

    If the node rejects the purchase order or lets it expire, that node is excluded and the group is searched again. A merged release breaks up and each group is searched on its own.

    Systemvendor-connectivity
    EventPurchaseOrderRejected
    PolicyWhenever a node rejects or lets a purchase order expire, skip that node and search again
    CommandHandleNodeRefusalstarted by the policy
    AggregateAssignment
    EventFulfillmentReassigned
    EventFulfillmentUnsourceable
    EventAssignmentsDeconsolidatedanalytics stream only
    Systemlinehaul-transportation
    PolicyUpdates its view of the group's node
    Systemdelivery-promise
    PolicyFlags the promise as at risk when no node is left

    Source: application/usecases/commands.go · domain/assignment/commands.go · adapters/inbound/kafka/handlers_partner.go

  8. Record the shipment

    When the node confirms that the purchase order shipped, the group is marked shipped with its tracking numbers, and a merged release ships all its groups.

    Systemvendor-connectivity
    EventVendorShipmentConfirmed
    PolicyWhenever the node confirms a shipment, mark the group shipped with its tracking numbers
    CommandMarkShippedstarted by the policy
    AggregateAssignment
    EventFulfillmentShipped
    Systemcustomer-ordering
    PolicyMarks the group shipped and stores the tracking numbers
    Systemdelivery-promise
    PolicyRecords the packages of the group to judge the promise
    Systemcustomer-payments
    PolicyCaptures the payment of the group

    Source: application/usecases/commands.go · domain/assignment/commands_lifecycle.go

  9. Record the delivery

    Each delivered package is remembered. The group counts as delivered only when its last package arrives.

    Systemshipping-and-tracking
    EventPackageDelivered
    PolicyWhenever a package is delivered, record it; the last package delivers the group
    CommandMarkDeliveredstarted by the policy
    AggregateAssignment
    EventFulfillmentDeliveredanalytics stream only

    Source: application/usecases/commands.go · domain/assignment/commands_lifecycle.go · adapters/inbound/kafka/handlers_logistics.go

  10. Cancel a group before it locks

    A cancelled order cancels its groups while they are queued, released or unsourceable. A locked group, or a member of a merged release, refuses the cancellation and the order keeps it.

    Systemcustomer-ordering
    EventCustomerOrderCancelled
    PolicyWhenever an order is cancelled, cancel its groups that are not locked and refuse the others
    CommandCancelAssignmentstarted by the policy
    AggregateAssignment
    EventFulfillmentCancelled
    EventFulfillmentCancelRefused
    Systemvendor-connectivity
    PolicyCancels the purchase order of a released group
    Systemlinehaul-transportation
    PolicyUpdates its view of the group
    Systemseller-inbound
    PolicyRemoves the group's lines from its demand view
    Systemcustomer-payments
    PolicyLets go of the payment hold for the group
    Systemcustomer-ordering
    PolicyConfirms the cancellation, or keeps the group when refused

    Source: application/usecases/cancel_revise.go · domain/assignment/commands_lifecycle.go

  11. Re-check a group after a promise change

    When delivery-promise revises a promise, the group gets the new deadline and its exclusions are reset. A merged release that no longer fits the window is withdrawn and its groups are searched again.

    Systemdelivery-promise
    EventPromiseRevised
    PolicyWhenever a promise is revised, apply the new deadline and search again if the group is still queued
    CommandApplyRevisedPromisestarted by the policy
    AggregateAssignment
    EventFulfillmentConstraintRevised
    EventFulfillmentReleaseWithdrawn
    EventAssignmentsDeconsolidatedanalytics stream only
    Systemvendor-connectivity
    PolicyCancels the purchase order of the withdrawn release

    Source: application/usecases/cancel_revise.go · domain/assignment/commands_revision.go · 0015-carrier-and-follower-consolidation-at-release.md

  12. Follow a moved pickup

    If linehaul moves a booking to another departure, the locked group points at the new pickup. The node never changes. A failed booking changes nothing here.

    PolicyWhenever a booking moves to another departure, point the locked group at the new pickup
    CommandRecordPickupMovedstarted by the policy
    AggregateAssignment

    Source: application/usecases/commands.go · domain/assignment/commands_revision.go

  13. Keep the network map

    Nodes, their profiles and status, lanes, regions and service areas come from node-topology. Order-sourcing keeps a copy so a search never needs a live call.

    Systemnode-topology
    EventLaneOpened
    PolicyWhenever a node, lane, region or service area changes, update the local network copies
    CommandProjector.LaneOpenedstarted by the policy
    Read model · kept up to dateNetwork graph
    Read model · kept up to dateNode profiles

    Source: application/usecases/projector.go · adapters/inbound/kafka/handlers_logistics.go

  14. Keep the departures copy

    Linehaul announces departures, capacity changes and cancellations. A route can only start on a departure that this copy still shows as usable.

    Systemlinehaul-transportation
    EventDepartureScheduled
    PolicyWhenever a departure is scheduled, resized or cancelled, update the local departures copy
    CommandProjector.DepartureScheduledstarted by the policy
    Read model · kept up to dateNetwork graph

    Source: application/usecases/projector.go · adapters/inbound/kafka/handlers_logistics.go

  15. Keep the delivery waves copy

    Last-mile delivery announces its waves, capacity changes, cancellations and per-stop costs. A route ends on a wave of the destination's station.

    Systemlast-mile-delivery
    EventDeliveryWaveScheduled
    PolicyWhenever a wave is scheduled, resized, cancelled or priced, update the local waves copy
    CommandProjector.WaveScheduledstarted by the policy
    Read model · kept up to dateNetwork graph

    Source: application/usecases/projector.go · adapters/inbound/kafka/handlers_logistics.go

  16. Keep the availability copy

    Offer-availability reports what each node can ship. A node only qualifies when every line of the group is listed, not suppressed and in stock.

    Systemoffer-availability
    EventListingAvailabilityChanged
    PolicyWhenever a listing's stock changes, update the local availability copy
    CommandProjector.ListingAvailabilityChangedstarted by the policy
    Read model · kept up to dateAvailability copy

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

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.

Opportunities

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