Integration
How order-sourcing fits with the rest of the fleet, with the status of every edge. Three words are used strictly:
- Built: code on this repository's
developthat does the job. - Verified: the other side was read on its own local
origin/developand names the same type. The clones were fetched and read atvendor-connectivitya413d73,linehaul-transportation6435eb2,delivery-promiseedfcd56,customer-ordering6fd1f88,seller-inbound70dff25andcustomer-paymentse5aef0c(a localgit grepof the handler files). - Not read: the producer side of the nine upstream topics was not re-read for this page; the types come from this service's
handlers and
apis/asyncapi.yaml.
This context calls no sibling: it has no outbound HTTP client, no MCP client and no A2A client
(TestA2AHasNoOutboundClient), and every decision is made from local read models fed by events (ADR 0003).
The single broker is the platform's one Kafka; cmd/api refuses to boot without KAFKA_BROKERS and the nine consumer group ids.
Edge map
Source: internal/adapters/inbound/kafka/handlers.go (consumed side), internal/adapters/outbound/kafka/encoder.go and
internal/domain/assignment/events.go (published side), apis/asyncapi.yaml, and the six downstream handler files named
below. Solid edges carry Kafka events; the dotted edge is the read surface.
Upstream: what Order Sourcing consumes
Nine topics, 34 types, nine consumer groups (the full list with fields is the event catalogue).
| Producer | Protocol and topic | Contract (types) | What it drives | Status |
|---|---|---|---|---|
| customer-ordering | Kafka, retailnetwork.customer-ordering.events | CustomerOrderPlaced, CustomerOrderCancelled | QueueAssignment, CancelAssignment | Built. Dispatch on the full type; per-group queueing and idempotency on (orderId, groupNo). |
| delivery-promise | Kafka, retailnetwork.delivery-promise.events | PromiseRevised, PromiseBookExhausted | ApplyRevisedPromise; book pressure read model | Built. A revision not above the applied revisionNo is ignored. |
| vendor-connectivity | Kafka, retailnetwork.vendor-connectivity.events | PurchaseOrderAccepted, PurchaseOrderRejected, PurchaseOrderExpired, VendorShipmentConfirmed | LockAssignment, HandleNodeRefusal, MarkShipped | Built. Each outcome carries assignmentId and, for the purchase-order ones, releaseNo. |
| shipping-and-tracking | Kafka, retailnetwork.shipping-and-tracking.events | PackageDelivered | MarkDelivered | Built. One event per package; the group delivers on the last. |
| linehaul-transportation | Kafka, retailnetwork.linehaul-transportation.events | DepartureScheduled, DepartureCapacityChanged, DepartureCancelled, BookingMoved, BookingFailed | departures read model; RecordPickupMoved; RecordProcessed | Built. BookingFailed is only recorded as processed. |
| last-mile-delivery | Kafka, retailnetwork.last-mile-delivery.events | DeliveryWaveScheduled, DeliveryWaveCapacityChanged, DeliveryWaveCancelled, WaveCostDeclared | waves read model | Built. |
| node-topology | Kafka, retailnetwork.node-topology.events | NodeRegistered, NodeOperationalProfileDeclared, NodeActivated, NodeSuspended, NodeRetired, LaneOpened, LaneClosed, LaneCostDeclared, ServiceAreaAssigned, RegionDefined | nodes, lanes, service areas, regions | Built. Upserts; newer profileRevision / assignmentVersion wins. |
| offer-availability | Kafka, retailnetwork.offer-availability.events | ListingCreated, ListingAvailabilityChanged, ListingSuppressed, ListingRestored, CatalogItemDiscontinued | listings and discontinued items | Built. An older asOf is ignored. |
| node-performance | Kafka, retailnetwork.node-performance.events | NodeScorecardUpdated | scorecards | Built. An older computedAt is ignored. |
All of them are CloudEvents 1.0 in structured mode, decoded only by internal/adapters/kafka/cloudevents.
How every consumed message is handled
(internal/adapters/inbound/kafka/consumer.go, deadletter.go)
- Dispatch on the full
type; every other type on those topics is ignored and its offset committed. - A message that is not a valid CloudEvents 1.0 event is logged at WARN and committed past; it is not dead-lettered.
- The claim of the CloudEvents
id(tableprocessed_events) and the effect commit in one Postgres transaction; the Kafka offset is committed afterwards (at least once). A redelivered id changes nothing. - A payload that can never be applied (undecodable
data, a validation error) goes to<topic>.dlqat once. An event the aggregate can no longer take (not found, illegal transition, locked, release not pending, stale revision or version) is logged and acknowledged. - A transient failure is retried with capped backoff (200 ms to 5 s), 5 attempts, then published to
<topic>.dlqwithx-dlq-*headers. Shutdown never dead-letters. - Group ids come from
<PRODUCER>_CONSUMER_GROUPwith no default; a missing one is a boot error naming it.
Downstream: what Order Sourcing publishes
Fifteen events through the transactional outbox, at least once, key = assignmentId (policy for SourcingPolicyPublished): nine to retailnetwork.order-sourcing.events
(the eight integration events and FulfillmentReleaseWithdrawn, ADR 0015),
FulfillmentQueued, FulfillmentSourcingDecided, FulfillmentDelivered, SourcingPolicyPublished, AssignmentsConsolidated and AssignmentsDeconsolidated to retailnetwork.order-sourcing.analytics only. FulfillmentReleasedToNode carries the optional policyVersion and effectiveCostCents (ADR 0014); consumers decode them tolerantly. This
context's own cmd/os-projector (ADR 0013) consumes both topics into its analytical database.
| Consumer | Protocol and topic | Contract | Status |
|---|---|---|---|
| vendor-connectivity | Kafka, retailnetwork.order-sourcing.events | FulfillmentReleasedToNode (becomes a purchase order, idempotent on assignmentId + releaseNo), FulfillmentCancelled, FulfillmentReleaseWithdrawn (a merged release is dissolved before the vendor acknowledged it, ADR 0015) | Built + verified. internal/adapters/inbound/kafka/consumers.go on its origin/develop handles exactly these three types. |
| linehaul-transportation | same | FulfillmentReleasedToNode, FulfillmentReassigned, FulfillmentLocked, FulfillmentCancelled | Built + verified. internal/adapters/inbound/kafka/handlers.go handles these four. |
| delivery-promise | same | FulfillmentLocked, FulfillmentShipped, FulfillmentUnsourceable | Built + verified. internal/adapters/inbound/kafka/dispatch.go handles these three; FulfillmentUnsourceable is what asks for a re-promise, and its PromiseRevised answer comes back as upstream traffic. FulfillmentLocked also moves the promise's capacity charge to the locked node and pickup departure when that differs from the quoted one (rehomeOnLock in internal/application/usecases/rehome.go). |
| customer-ordering | same | FulfillmentLocked, FulfillmentShipped, FulfillmentUnsourceable, FulfillmentCancelled, FulfillmentCancelRefused | Built + verified. internal/adapters/inbound/kafka/handlers.go handles these five. |
| seller-inbound | same | FulfillmentReleasedToNode, FulfillmentCancelled | Built + verified. internal/adapters/inbound/kafka/consumers.go (SourcingHandlers) handles these two; they feed its demand view. |
| customer-payments | same | FulfillmentShipped, FulfillmentCancelled, FulfillmentUnsourceable | Built + verified. internal/adapters/inbound/kafka/handlers.go (orderSourcingHandlers) handles these three as facts on the payment authorization. |
| any consumer | same | FulfillmentConstraintRevised | Published, no consumer found in the six clones above. |
| analytics read side | Kafka, retailnetwork.order-sourcing.analytics | FulfillmentQueued, FulfillmentSourcingDecided, FulfillmentDelivered | Consumed in this repository by cmd/os-projector (ADR 0013), which projects FulfillmentQueued and FulfillmentSourcingDecided into the analytical database (the decoder internal/adapters/inbound/kafka/analytics_decode.go maps only FulfillmentQueued, FulfillmentSourcingDecided and FulfillmentUnsourceable, so FulfillmentDelivered is not projected); no domain consumer is known. |
| network-ops planner, console, agents | REST GET /assignments, GET /assignments/{id}, POST /assignments/{id}/reoptimisations; MCP; A2A | apis/openapi.yaml, MCP tools, API overview | Built. The web remote order_sourcing_mfe (web/, ADR 0007) calls only this context's own /api/order-sourcing. |
Compared with the design pack in warehouse-docs (domain-events), the downstream handlers on origin/develop read more than the
pack lists: delivery-promise also reads FulfillmentShipped, and customer-ordering also reads FulfillmentCancelled and
FulfillmentCancelRefused. The code of each consumer is the reference.
Infrastructure wiring
The Kong routes /api/order-sourcing (prefix stripped), /api/mcp/order-sourcing (rewritten to /mcp) and
/api/a2a/order-sourcing (rewritten to /) come from warehouse-infra helm-values/order-sourcing.yaml, summarised in the
Runbook. The service needs Postgres (all three binaries) and the platform Kafka broker
(cmd/api only); it creates no topic through an admin API.
Absent edges (on purpose)
- No REST, MCP or A2A call to any sibling, in either direction.
sync_callsis empty; a neighbour outage delays freshness of the read models, never a release. - No edge to
network-fulfillment. The hard boundary: no retail-network context calls a warehouse-systems fleet service or reads a fleet topic. The fleet reaches this context's decisions only as purchase orders it polls fromvendor-connectivity's Vendor API. - No payment, notification or returns edge: no code on either side.
- No PII crosses any edge. Only the destination postal prefix is stored, never an address or a person; a release carries no ship-to data.
- No auth on any inbound surface (fleet decision).
Failure behaviour
| Situation | Behaviour |
|---|---|
| Postgres down at boot | Migrations and the first ping are retried by bootretry (5 attempts, about 15 s of backoff), then the process exits 1 and the orchestrator restarts it. |
| Postgres down at runtime | REST writes fail (500 internal-error); consumers fail transiently, retry and after 5 attempts dead-letter; /readyz answers 503 dependency-unavailable. cmd/mcp and cmd/a2a answer tool or skill errors as internal-error. |
| Kafka down | REST reads and the writes that only touch Postgres keep working: the aggregate and its outbox_events row commit in one transaction. /readyz turns 503 (not ready: kafka), so the pod leaves the Service. The relay retries every interval and rows wait; consumers block and resume. |
| Downstream consumer down | Events wait in the topic; its own consumer group resumes. Nothing in this service blocks on it. |
| Duplicate or replayed event | The inbox makes it a no-op; the outbox keeps the same CloudEvents id. |
| Late outcome of an old release | releaseNo is not the pending one: logged and acknowledged. |
| Cancel after the lock | Refused with FulfillmentCancelRefused; the state does not change. |
| Stale read model (a node, departure or listing event is late) | Decisions use the data as it stands; the sweep re-optimises QUEUED assignments every SWEEP_INTERVAL and the release re-checks the candidate against fresh models. |
| Poison message | Dead-lettered; the partition moves on. Nothing in this repository reads or replays a .dlq topic. |
Outbox row parked at OUTBOX_MAX_ATTEMPTS | Skipped and logged once at ERROR; later events of the same assignment can overtake it. Re-arm it as in the Runbook. |