Retail network · Supporting domain · EventStorming board

last-mile-delivery

Runs the final leg: delivery waves at a station, packages taken in when loads arrive, partner routes, delivery attempts, retries and returns.

GitHub ↗ · Documentation ↗ · Architecture check · Briefings

events published
13
commands
16
policies
16
read models
2
hot spots
5

The story in 4 key events

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

  1. Pivotal eventDeliveryWaveScheduled
  2. Pivotal eventPackageOutForDelivery
  3. Pivotal eventDeliveryAttempted
  4. Pivotal eventPackageReturnInitiated

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

Tells (3): contexts that react to its events

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. Keep the list of delivery stations

    Node-topology announces every node. Only delivery stations matter here; a wave or a partner can be set up only for a station that is on this list.

    Systemnode-topology
    EventNodeRegistered
    PolicyWhenever a node is registered, keep it only if it is a delivery station
    CommandApplyNodeRegisteredstarted by the policy
    Read model · kept up to dateStations

    Source: application/usecases/consumers.go · adapters/inbound/kafka/consumers.go

  2. Keep the stop of each labelled package

    When a label is issued, the package's stop key and order assignment are kept. Packages for one address share a stop, so they take one place in a wave.

    PolicyWhenever a label is issued, keep the package's stop key; a label without a usable key is ignored
    CommandApplyLabelIssuedstarted by the policy
    Read model · kept up to datePackage stops

    Source: application/usecases/consumers.go · adapters/inbound/kafka/consumers.go

  3. Schedule a delivery wave

    A station planner opens a wave: an induction cut-off, a delivery window and how many stops it can take. Packages already waiting at the station are taken into it, oldest first.

    ActorStation planner
    Read modelStations
    CommandScheduleWavePOST /waves
    AggregateDeliveryWave
    EventDeliveryWaveScheduled
    EventDeliveryWaveCapacityChanged
    Systemdelivery-promise
    PolicyAdds the wave to its copy so promises can use it
    Systemorder-sourcing
    PolicyAdds the wave to the network copy its search uses

    Source: application/usecases/waves.go · application/usecases/induct.go · domain/wave/wave.go

  4. Take in packages when a load arrives

    When a load reaches a delivery station, each package goes into the earliest wave that still accepts it. A package no wave accepts waits at the station and a deferral is announced.

    PolicyWhenever a load reaches a delivery station, put each package on the earliest open wave or defer it
    Read modelStations
    Read modelPackage stops
    CommandInductOnArrivalstarted by the policy
    AggregateDeliveryWave
    EventDeliveryWaveCapacityChanged
    EventPackageInductionDeferred
    Systemdelivery-promise
    PolicyUpdates the room left on the wave; a deferred package flags its promise as at risk
    Systemorder-sourcing
    PolicyUpdates the room left on the wave in its network copy

    Source: application/usecases/consumers.go · application/usecases/induct.go · domain/history/history.go

  5. Declare what a stop costs

    A station planner declares the cost of one stop on a wave that is still running. Order-sourcing adds it to the cost of the routes it compares.

    ActorStation planner
    CommandDeclareWaveCostPOST /waves/{waveId}/cost-declarations
    AggregateDeliveryWave
    EventWaveCostDeclared
    Systemorder-sourcing
    PolicyUses it as the wave's per-stop cost when comparing routes

    Source: application/usecases/waves.go · domain/wave/wave.go · 0011-wave-stop-cost-declaration.md

  6. Declare the carbon a stop emits

    A station planner declares the carbon, in grams of CO2-equivalent, of one stop on a wave that is still running. Nothing reads it yet.

    ActorStation planner
    CommandDeclareWaveEmissionPOST /waves/{waveId}/emission-declarations
    AggregateDeliveryWave
    EventWaveEmissionDeclared

    Source: application/usecases/waves.go · domain/wave/events.go · 0016-wave-stop-emission-declaration.md

  7. Close induction on a wave

    A station planner stops taking packages into a wave, so routes can be planned on a fixed set of packages.

    ActorStation planner
    CommandCloseInductionPOST /waves/{waveId}/induction-closures
    AggregateDeliveryWave

    Source: application/usecases/waves.go · domain/wave/wave.go

  8. Cancel a wave

    A station planner cancels a wave that is still open. Its packages move to the next eligible wave in the same step, or wait at the station.

    ActorStation planner
    CommandCancelWavePOST /waves/{waveId}/cancellations
    AggregateDeliveryWave
    EventDeliveryWaveCancelled
    Systemdelivery-promise
    PolicyFlags promises whose route used the wave as at risk
    Systemorder-sourcing
    PolicyMarks the wave as cancelled in its network copy

    Source: application/usecases/waves.go · domain/wave/wave.go

  9. Contract a delivery partner

    A station planner signs up a delivery service partner for a station, with the van capacity of its routes.

    ActorStation planner
    Read modelStations
    CommandContractPartnerPOST /partners
    AggregateDeliveryServicePartner

    Source: application/usecases/partners.go · domain/partner/partner.go

  10. Deactivate a delivery partner

    A station planner deactivates a partner. It gets no new routes; routes already planned are not re-checked.

    ActorStation planner
    CommandDeactivatePartnerPOST /partners/{dspId}/deactivations
    AggregateDeliveryServicePartner

    Source: application/usecases/partners.go · domain/partner/partner.go

  11. Plan a partner's route in a wave

    A station planner gives a partner a numbered list of stops from a wave whose induction is closed. The route must fit the van, use only packages of the wave and keep one address in one stop.

    ActorStation planner
    CommandPlanRoutePOST /routes
    AggregateRoute
    EventRoutePlannedanalytics stream only

    Source: application/usecases/routes.go · domain/route/route_planning.go

  12. Dispatch a wave

    A station planner sends the wave out. Packages that no route holds are moved to the next wave, and a wave with no route completes at once.

    ActorStation planner
    CommandDispatchWavePOST /waves/{waveId}/dispatches
    AggregateDeliveryWave

    Source: application/usecases/waves.go · domain/wave/wave.go

  13. Start a route

    An operator starts a planned route of a dispatched wave. Every package goes out, for delivery or for pickup, and each stop gets an arrival window of up to two hours inside the wave's delivery window.

    ActorOperator
    CommandStartRoutePOST /routes/{routeId}/starts
    AggregateRoute
    EventPackageOutForDelivery
    EventPackagePickupOut
    EventStopEtaWindowAssigned
    Systemshipping-and-tracking
    PolicyRecords an out-for-delivery scan and keeps the arrival window of each package

    Source: application/usecases/routes.go · domain/route/route_start.go · domain/route/route_eta.go · 0017-return-pickup-inductions.md

  14. Record a delivery attempt

    The driver records for each package whether it was delivered or failed. A package is delivered at most once, and the route completes when every package has an attempt.

    ActorDriver
    CommandRecordAttemptPOST /routes/{routeId}/attempts
    AggregateRoute
    EventDeliveryAttempted
    Systemshipping-and-tracking
    PolicyRecords a delivered or failed-delivery scan for the package

    Source: application/usecases/routes.go · domain/route/route.go

  15. Retry a failed delivery, or send it back

    After a failed attempt the package goes on the next eligible wave. After the third failure it is not retried: a return to sender starts.

    Event · earlierDeliveryAttempted
    PolicyWhenever an attempt fails, place the package on the next wave unless it was the third failure
    CommandRetryNextWavestarted by the policy
    AggregateHistory
    EventPackageReturnInitiated
    Systemshipping-and-tracking
    PolicyMarks the package as returned to sender

    Source: application/usecases/routes.go · domain/history/history.go

  16. Flag a drop-off point that keeps failing

    Each attempt updates the profile of its stop. After two failed visits for not-home or access problems within 60 days, the point is flagged for the packages affected. A flag changes no route.

    Event · earlierDeliveryAttempted
    PolicyWhenever an attempt is recorded, update the stop's profile; two failed visits flag the point
    CommandObservestarted by the policy
    AggregateProfile
    EventDeliveryPointFlagged
    Systemshipping-and-tracking
    PolicyKeeps the flag on every package of the stop

    Source: application/usecases/delivery_points.go · domain/deliverypoint/observe.go · 0014-delivery-point-profile.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.

Opportunities

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