Skip to main content

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​

AxisVerdict
DomainCore. See the Core domain chart and Subdomain classification.
Business modelCost reducer (cost-to-serve) and speed protector.
EvolutionCustom-built.

Domain roles​

RoleApplies?Evidence in the code
Execution (assignment)Yes, primaryOwns the FulfillmentAssignment lifecycle: QueueAssignment, ReleaseToNode, HandleNodeRefusal, LockAssignment, MarkShipped, MarkDelivered, CancelAssignment, ApplyRevisedPromise (Use cases)
Analysis (optimisation)YesReoptimiseAssignment and the pure search sourcing.Search over five event-fed read models
Enforcer (path lock)YesErrAssignmentLocked, ErrCancelAfterLock, ErrNodeExcluded, ErrReleaseInFlight in internal/domain/assignment/errors.go

Inbound communication​

CollaboratorMessagesTypeChannelRelationship
customer-orderingCustomerOrderPlaced, CustomerOrderCancelledEventKafka retailnetwork.customer-ordering.eventsCustomer/Supplier
delivery-promisePromiseRevised, PromiseBookExhaustedEventKafka retailnetwork.delivery-promise.eventsCustomer/Supplier
vendor-connectivityPurchaseOrderAccepted, PurchaseOrderRejected, PurchaseOrderExpired, VendorShipmentConfirmedEventKafka retailnetwork.vendor-connectivity.eventsCustomer/Supplier
shipping-and-trackingPackageDeliveredEventKafka retailnetwork.shipping-and-tracking.eventsConformist
node-topologyNodeRegistered, NodeOperationalProfileDeclared, NodeActivated, NodeSuspended, NodeRetired, LaneOpened, LaneClosed, LaneCostDeclared, ServiceAreaAssigned, RegionDefinedEventKafka retailnetwork.node-topology.eventsConformist
offer-availabilityListingCreated, ListingAvailabilityChanged, ListingSuppressed, ListingRestored, CatalogItemDiscontinuedEventKafka retailnetwork.offer-availability.eventsConformist
linehaul-transportationDepartureScheduled, DepartureCapacityChanged, DepartureCancelled, BookingMoved, BookingFailedEventKafka retailnetwork.linehaul-transportation.eventsConformist
last-mile-deliveryDeliveryWaveScheduled, DeliveryWaveCapacityChanged, DeliveryWaveCancelled, WaveCostDeclaredEventKafka retailnetwork.last-mile-delivery.eventsConformist
node-performanceNodeScorecardUpdatedEventKafka retailnetwork.node-performance.eventsConformist
Network-ops planner, agentsListAssignments, GetAssignmentQueryREST GET /assignments, GET /assignments/{id}; MCP list_assignments, get_assignment; A2A find_assignments, assignment_detailOpen Host (UI)
Network-ops plannerReoptimiseAssignmentCommandREST POST /assignments/{id}/reoptimisationsOpen Host (UI)
Own sweepReleaseToNode, ReoptimiseAssignmentCommandin-process timer, SWEEP_INTERVALInternal

Outbound communication​

All events: source /retailnetwork/order-sourcing, subject and Kafka key assignmentId, dataschema urn:retailnetwork:order-sourcing:<stream>:<EventName>:v1.

CollaboratorMessageTopicRelationship
none (analytics only)FulfillmentQueued, FulfillmentSourcingDecided, FulfillmentDelivered, AssignmentsConsolidated, AssignmentsDeconsolidated, SourcingPolicyPublishedretailnetwork.order-sourcing.analyticsPublished Language
vendor-connectivity, linehaul-transportation, seller-inboundFulfillmentReleasedToNoderetailnetwork.order-sourcing.eventsCustomer/Supplier; not declared (seller-inbound)
linehaul-transportationFulfillmentReassignedeventsCustomer/Supplier
delivery-promise, customer-ordering, linehaul-transportationFulfillmentLockedeventsCustomer/Supplier; Conformist (customer-ordering)
delivery-promise, customer-ordering, customer-paymentsFulfillmentShippedeventsConformist
delivery-promise, customer-ordering, customer-paymentsFulfillmentUnsourceableeventsCustomer/Supplier (delivery-promise); Conformist (customer-ordering, customer-payments)
vendor-connectivity, linehaul-transportation, customer-ordering, seller-inbound, customer-paymentsFulfillmentCancelledeventsCustomer/Supplier; Conformist (customer-payments); not declared (seller-inbound)
customer-orderingFulfillmentCancelRefusedeventsConformist
vendor-connectivityFulfillmentReleaseWithdrawneventsCustomer/Supplier
none foundFulfillmentConstraintRevisedeventsPublished Language
noneno synchronous calln/an/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​

  1. The assigned node may differ from the witness node. The only hard constraint is that the candidate still meets deliverByLatest (ErrCandidateBreaksPromise).
  2. Free while queued, constrained after release, final after acceptance. Reoptimise works only in QUEUED; after release the node changes only through RefuseRelease; after PurchaseOrderAccepted the assignment is LOCKED.
  3. Fill-or-kill. A group goes to one node in full; at most one release is pending (ErrReleaseInFlight).
  4. Never break a promise silently. No node left means UNSOURCEABLE and FulfillmentUnsourceable; a revised promise re-searches (ApplyRevisedPromise).
  5. 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.
  6. A refusing node is excluded for the current promise revision (ErrNodeExcluded); a higher revisionNo resets the list.
  7. Release late, but in time to be acknowledged: best pickup cutoff minus handling time minus 30 minutes; SAME_DAY at once.
  8. 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-connectivity echoes assignmentId and releaseNo on 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-promise answers FulfillmentUnsourceable with a revised promise or judges the promise broken later.

Verification metrics​

MetricComputed fromWhy
Groups by outcomesourcing.groups.sourced by outcome and reason (see Observability)Share created unsourceable or failed
First-release lock ratefirst FulfillmentReleasedToNode (releaseNo 1) followed by FulfillmentLockedQuality of the ranking and of node declarations
Reassignments per 1,000 groupsFulfillmentReassigned by reasonVendor reliability versus queue churn
Non-witness assignment shareFulfillmentLocked.nodeId differs from witnessNodeIdHow much late optimisation is used
Release lateness p95log queue sweep and releasedAt minus releaseAtThe queue fires on time
Stale-version conflicts409 stale-assignment-version, concurrent-updateContention 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):

  • ApplyRevisedPromise raises FulfillmentConstraintRevised and works in every non-terminal state; exclusions reset with the higher revisionNo (ADR 0002 A9, A10).
  • An UNSOURCEABLE assignment can be cancelled; a cancel after the lock is refused with FulfillmentCancelRefused.
  • A group with no candidate is UNSOURCEABLE at once, so there is no releaseAt without a candidate.
  • A multi-package group is DELIVERED when its last package is.
  • The promise-book capacity charge no longer stays on the witness node: when FulfillmentLocked names another node or pickup departure, delivery-promise moves the charge there (rehomeOnLock, internal/application/usecases/rehome.go in 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 PurchaseOrderAccepted for a CANCELLED assignment is ErrIllegalTransition; 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. BookingMoved repoints 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.