Skip to main content

Last-Mile Delivery

last-mile-delivery is the bounded context that runs each delivery station of the retail network. A delivery station is a network-operated node (see warehouse-docs ADR 0004). The context publishes delivery waves: dispatch slots with an induct cutoff, a delivery window and a stop capacity, which delivery-promise and order-sourcing plan the last leg of every path on. When a load arrives at a station it inducts each package into the earliest wave that still has room, plans routes for independent delivery service partners (DSPs) within each van's stop capacity, and records every delivery attempt as DELIVERED or FAILED. A failed package goes into the next wave; after three failures it goes back to the sender.

AreaNetwork (retail network, tier logistics)
Subdomain classSupporting (reasoning)
Language / runtimeGo 1.27, hexagonal, real PostgreSQL and Kafka only
Binariescmd/api (REST, three Kafka consumers, outbox relay), cmd/mcp (read-only MCP), cmd/a2a (read-only A2A agent)
Consoleweb/, the Module Federation remote last_mile_mfe
RepositoryIQVO/last-mile-delivery

The business problem​

A promise is only as good as its last leg. delivery-promise quotes a delivery date only when it can show a witness path that ends in a delivery wave at the destination station; order-sourcing chooses the real path the same way. Both need to know, ahead of time and without a call, three things about every station: when a package must be at the station to make a wave (the induct cutoff), when that wave delivers (the delivery window), and how many more stops it can take (its stop capacity). This context owns those facts and keeps them true, and does the work behind them.

It is a context of its own because the last mile has a different clock and capacity unit from the middle mile (it counts stops, in waves and in vans, not packages on departures), because DSPs are independent businesses with their own vans, and because the promise needs a stable published fact it can consume as an event-fed read model.

What it owns​

AggregateOwns
DeliveryWaveone dispatch wave of one station on one service date: cutoff, window, stop capacity, the inducted packages grouped into stops; states OPEN, INDUCTION_CLOSED, DISPATCHED, COMPLETED, CANCELLED
Routeone partner's van route within a wave: ordered stops, attempts; states PLANNED, OUT_FOR_DELIVERY, COMPLETED
DeliveryServicePartneran independent delivery business contracted to a station, its van capacity; ACTIVE or INACTIVE
PackageAttemptHistoryper tracking number: where the package is in its last-mile life and how many attempts failed (at most 3)

The business decisions it makes: a package joins the earliest wave it arrived before that has stop capacity left; a route never exceeds its van's stop capacity; a package is delivered at most once, and a failed one returns to the station for the next wave, until the third failure returns it to the sender; a wave's times are ordered; an attempt is recorded only on a route that is out for delivery.

What it does not own​

Out of scopeWhere it lives
Ship-to addresses and any other PIIcustomer-ordering and shipping-and-tracking only
The customer-visible timeline, PackageDelivered as a journey stateshipping-and-tracking
Which delivery station serves a postal prefix, the node registrynode-topology (this context keeps a local read model of it)
Middle-mile departures and loadslinehaul-transportation
Quoting, holding and judging promisesdelivery-promise
Choosing the sourcing pathorder-sourcing
Customer returns routing, customer notificationfuture contexts
Route optimisation: the caller sends the stops, the context only validates the plannot modelled
Anything in the warehouse-systems fleetno edge; the only seam between the organisations is the Vendor API, which this context does not touch

Main capabilities​

  • Schedule and run waves: schedule, close induction, dispatch, cancel; capacity published on every change (Use cases).
  • Induct on arrival: consume LoadArrived, place each package, defer it when no wave takes it, sweep waiting packages when a new wave is scheduled.
  • Plan and run routes: plan within the van capacity, start (one PackageOutForDelivery per package and one StopEtaWindowAssigned per stop), record attempts, complete automatically.
  • Count failures: three failed attempts publish PackageReturnInitiated.
  • Publish facts: eleven CloudEvents types through a transactional outbox (Domain events).
  • Read surfaces for agents: MCP (three tools) and A2A (two skills) over the same read use cases (MCP tools, API reference).

Where to go next​

I want to...Page
understand the layout and processesArchitecture
run it and make the first callsQuickstart
set environment variablesConfiguration
deploy and operate itRunbook, Before the first release
watch itObservability
fix itTroubleshooting
test itTesting
see who it talks toIntegration, Context map
call itAPI reference, Event catalogue, MCP tools
learn the domainUbiquitous language, DDD artifacts, Use cases
read the decisionsADR index

This project is a domain-driven design study. It is not associated with, endorsed by or affiliated with any company; all names, figures and examples are illustrative or synthetic.