Bounded context canvas
Following the ddd-crew Bounded Context Canvas v5. Every message row below is
a handler or an event in the code on develop; the exact types and data fields are on the
event catalogue.
Canvas at a glance
Inbound collaborators feed the context (purpose, roles, business decisions), then the outbound ones it notifies. Solid arrows are commands, dotted arrows queries, thick arrows events; each names its channel and messages.
Inbound
Source: internal/adapters/inbound/kafka/handlers.go (Handlers.Topics), internal/adapters/inbound/http/server.go,
internal/adapters/inbound/mcp/tools.go, internal/adapters/inbound/a2a/skills.go, cmd/api/main.go (startSweep).
Outbound
Source: internal/adapters/outbound/kafka/encoder.go, internal/domain/assignment/events.go; the consumer lists are read from the
six downstream handler files named on Integration. There are no outbound commands or queries: this
context calls no other context synchronously.
Name
Order Sourcing (order-sourcing, code OS, CloudEvents tier commerce).
Purpose
To decide, as late as the promise allows, which node and path will actually fulfil each shipment group. The context keeps one
FulfillmentAssignment per shipment group in a virtual queue, re-optimises queued assignments against current capacity and cost,
releases the group to one node at the release point (a purchase order through vendor-connectivity), reassigns on rejection or
expiry excluding the refusing node, locks once the node commits, and hands an impossible group back to delivery-promise as
unsourceable. It holds no PII and calls no other context synchronously.
Strategic classification
| Axis | Verdict |
|---|---|
| Domain | Core. See the Core domain chart and Subdomain classification. |
| Business model | Cost reducer (cost-to-serve) and speed protector. |
| Evolution | Custom-built. |
Domain roles
| Role | Applies? | Evidence in the code |
|---|---|---|
| Execution (assignment) | Yes, primary | Owns the FulfillmentAssignment lifecycle: QueueAssignment, ReleaseToNode, HandleNodeRefusal, LockAssignment, MarkShipped, MarkDelivered, CancelAssignment, ApplyRevisedPromise (Use cases) |
| Analysis (optimisation) | Yes | ReoptimiseAssignment and the pure search sourcing.Search over five event-fed read models |
| Enforcer (path lock) | Yes | ErrAssignmentLocked, ErrCancelAfterLock, ErrNodeExcluded, ErrReleaseInFlight in internal/domain/assignment/errors.go |
Inbound communication
| Collaborator | Messages | Type | Channel | Relationship |
|---|---|---|---|---|
customer-ordering | CustomerOrderPlaced, CustomerOrderCancelled | Event | Kafka retailnetwork.customer-ordering.events | Customer/Supplier |
delivery-promise | PromiseRevised, PromiseBookExhausted | Event | Kafka retailnetwork.delivery-promise.events | Customer/Supplier |
vendor-connectivity | PurchaseOrderAccepted, PurchaseOrderRejected, PurchaseOrderExpired, VendorShipmentConfirmed | Event | Kafka retailnetwork.vendor-connectivity.events | Customer/Supplier |
shipping-and-tracking | PackageDelivered | Event | Kafka retailnetwork.shipping-and-tracking.events | Conformist |
node-topology | NodeRegistered, NodeOperationalProfileDeclared, NodeActivated, NodeSuspended, NodeRetired, LaneOpened, LaneClosed, LaneCostDeclared, ServiceAreaAssigned, RegionDefined | Event | Kafka retailnetwork.node-topology.events | Conformist |
offer-availability | ListingCreated, ListingAvailabilityChanged, ListingSuppressed, ListingRestored, CatalogItemDiscontinued | Event | Kafka retailnetwork.offer-availability.events | Conformist |
linehaul-transportation | DepartureScheduled, DepartureCapacityChanged, DepartureCancelled, BookingMoved, BookingFailed | Event | Kafka retailnetwork.linehaul-transportation.events | Conformist |
last-mile-delivery | DeliveryWaveScheduled, DeliveryWaveCapacityChanged, DeliveryWaveCancelled, WaveCostDeclared | Event | Kafka retailnetwork.last-mile-delivery.events | Conformist |
node-performance | NodeScorecardUpdated | Event | Kafka retailnetwork.node-performance.events | Conformist |
| Network-ops planner, agents | ListAssignments, GetAssignment | Query | REST GET /assignments, GET /assignments/{id}; MCP list_assignments, get_assignment; A2A find_assignments, assignment_detail | Open Host (UI) |
| Network-ops planner | ReoptimiseAssignment | Command | REST POST /assignments/{id}/reoptimisations | Open Host (UI) |
| Own sweep | ReleaseToNode, ReoptimiseAssignment | Command | in-process timer, SWEEP_INTERVAL | Internal |
Outbound communication
All events: source /retailnetwork/order-sourcing, subject and Kafka key assignmentId, dataschema
urn:retailnetwork:order-sourcing:<stream>:<EventName>:v1.
| Collaborator | Message | Topic | Relationship |
|---|---|---|---|
| none (analytics only) | FulfillmentQueued, FulfillmentSourcingDecided, FulfillmentDelivered, AssignmentsConsolidated, AssignmentsDeconsolidated, SourcingPolicyPublished | retailnetwork.order-sourcing.analytics | Published Language |
vendor-connectivity, linehaul-transportation, seller-inbound | FulfillmentReleasedToNode | retailnetwork.order-sourcing.events | Customer/Supplier; not declared (seller-inbound) |
linehaul-transportation | FulfillmentReassigned | events | Customer/Supplier |
delivery-promise, customer-ordering, linehaul-transportation | FulfillmentLocked | events | Customer/Supplier; Conformist (customer-ordering) |
delivery-promise, customer-ordering, customer-payments | FulfillmentShipped | events | Conformist |
delivery-promise, customer-ordering, customer-payments | FulfillmentUnsourceable | events | Customer/Supplier (delivery-promise); Conformist (customer-ordering, customer-payments) |
vendor-connectivity, linehaul-transportation, customer-ordering, seller-inbound, customer-payments | FulfillmentCancelled | events | Customer/Supplier; Conformist (customer-payments); not declared (seller-inbound) |
customer-ordering | FulfillmentCancelRefused | events | Conformist |
vendor-connectivity | FulfillmentReleaseWithdrawn | events | Customer/Supplier |
| none found | FulfillmentConstraintRevised | events | Published Language |
| none | no synchronous call | n/a | n/a |
Ubiquitous language
Full glossary: Ubiquitous language. Top terms: Fulfillment assignment, Virtual queue, Release, Path lock, Reassignment, Unsourceable, and the value objects Promise constraint, Candidate, Release record, Excluded node.
Business decisions
- The assigned node may differ from the witness node. The only hard constraint is that the candidate still meets
deliverByLatest(ErrCandidateBreaksPromise). - Free while queued, constrained after release, final after acceptance.
Reoptimiseworks only inQUEUED; after release the node changes only throughRefuseRelease; afterPurchaseOrderAcceptedthe assignment isLOCKED. - Fill-or-kill. A group goes to one node in full; at most one release is pending (
ErrReleaseInFlight). - Never break a promise silently. No node left means
UNSOURCEABLEandFulfillmentUnsourceable; a revised promise re-searches (ApplyRevisedPromise). - In-region first, when the operator says so. Money ranks candidates (ADR 0011), so a cheaper cross-region lane wins by default; cross-region still costs 1000 legacy points as a tie-break. The sourcing policy (ADR 0014) lets the operator add a cross-region surcharge and a cost-deviation budget inside which an in-region candidate wins. It is a lever, not a filter, and it is off until a policy is published.
- A refusing node is excluded for the current promise revision (
ErrNodeExcluded); a higherrevisionNoresets the list. - Release late, but in time to be acknowledged: best pickup cutoff minus handling time minus 30 minutes;
SAME_DAYat once. - Cancel only before the lock; later requests are refused with
FulfillmentCancelRefused.
Assumptions
- Every release goes to a vendor node: the search only considers active vendor-operated fulfilment centres, so every release
becomes a purchase order issued by
vendor-connectivity. vendor-connectivityechoesassignmentIdandreleaseNoon every purchase-order outcome, so a late outcome of an old release is recognised (ErrReleaseNotPending) and ignored.- The read models have caught up before the first release after a start; they are fed only by events.
delivery-promiseanswersFulfillmentUnsourceablewith a revised promise or judges the promise broken later.
Verification metrics
| Metric | Computed from | Why |
|---|---|---|
| Groups by outcome | sourcing.groups.sourced by outcome and reason (see Observability) | Share created unsourceable or failed |
| First-release lock rate | first FulfillmentReleasedToNode (releaseNo 1) followed by FulfillmentLocked | Quality of the ranking and of node declarations |
| Reassignments per 1,000 groups | FulfillmentReassigned by reason | Vendor reliability versus queue churn |
| Non-witness assignment share | FulfillmentLocked.nodeId differs from witnessNodeId | How much late optimisation is used |
| Release lateness p95 | log queue sweep and releasedAt minus releaseAt | The queue fires on time |
| Stale-version conflicts | 409 stale-assignment-version, concurrent-update | Contention between sweep, consumers and the planner |
Of these only the first is an instrument in the service; the others are derived from the event stream.
Open questions
Resolved by the build (the aggregator's earlier canvas listed them as gaps):
ApplyRevisedPromiseraisesFulfillmentConstraintRevisedand works in every non-terminal state; exclusions reset with the higherrevisionNo(ADR 0002 A9, A10).- An
UNSOURCEABLEassignment can be cancelled; a cancel after the lock is refused withFulfillmentCancelRefused. - A group with no candidate is
UNSOURCEABLEat once, so there is noreleaseAtwithout a candidate. - A multi-package group is
DELIVEREDwhen its last package is. - The promise-book capacity charge no longer stays on the witness node: when
FulfillmentLockednames another node or pickup departure,delivery-promisemoves the charge there (rehomeOnLock,internal/application/usecases/rehome.goin that repository). It keeps the charge on the quoted node, logged and not retried, when the departure is unknown, the locked node's book is full or closed, or no single owner there covers the lines. - Reason vocabularies are fixed in ADR 0004.
Still open:
- Acceptance after cancellation. A
PurchaseOrderAcceptedfor aCANCELLEDassignment isErrIllegalTransition; the consumer logs it and acknowledges. Nothing undoes the vendor's acceptance, so the vendor may still ship a cancelled group. - Book pressure only rises. No event says a book has room again; the penalty applies until the departure passes.
- A cancelled pickup departure after the lock.
BookingMovedrepoints a locked assignment; nothing handles a cancelled departure for a locked one. - Soft versus hard cross-region rule. Business decision 5 reads as a filter; the code applies a tie-break penalty and, with a published sourcing policy, a surcharge and a budget.