Skip to main content

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 develop that does the job.
  • Verified: the other side was read on its own local origin/develop and names the same type. The clones were fetched and read at vendor-connectivity a413d73, linehaul-transportation 6435eb2, delivery-promise edfcd56, customer-ordering 6fd1f88, seller-inbound 70dff25 and customer-payments e5aef0c (a local git grep of 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).

ProducerProtocol and topicContract (types)What it drivesStatus
customer-orderingKafka, retailnetwork.customer-ordering.eventsCustomerOrderPlaced, CustomerOrderCancelledQueueAssignment, CancelAssignmentBuilt. Dispatch on the full type; per-group queueing and idempotency on (orderId, groupNo).
delivery-promiseKafka, retailnetwork.delivery-promise.eventsPromiseRevised, PromiseBookExhaustedApplyRevisedPromise; book pressure read modelBuilt. A revision not above the applied revisionNo is ignored.
vendor-connectivityKafka, retailnetwork.vendor-connectivity.eventsPurchaseOrderAccepted, PurchaseOrderRejected, PurchaseOrderExpired, VendorShipmentConfirmedLockAssignment, HandleNodeRefusal, MarkShippedBuilt. Each outcome carries assignmentId and, for the purchase-order ones, releaseNo.
shipping-and-trackingKafka, retailnetwork.shipping-and-tracking.eventsPackageDeliveredMarkDeliveredBuilt. One event per package; the group delivers on the last.
linehaul-transportationKafka, retailnetwork.linehaul-transportation.eventsDepartureScheduled, DepartureCapacityChanged, DepartureCancelled, BookingMoved, BookingFaileddepartures read model; RecordPickupMoved; RecordProcessedBuilt. BookingFailed is only recorded as processed.
last-mile-deliveryKafka, retailnetwork.last-mile-delivery.eventsDeliveryWaveScheduled, DeliveryWaveCapacityChanged, DeliveryWaveCancelled, WaveCostDeclaredwaves read modelBuilt.
node-topologyKafka, retailnetwork.node-topology.eventsNodeRegistered, NodeOperationalProfileDeclared, NodeActivated, NodeSuspended, NodeRetired, LaneOpened, LaneClosed, LaneCostDeclared, ServiceAreaAssigned, RegionDefinednodes, lanes, service areas, regionsBuilt. Upserts; newer profileRevision / assignmentVersion wins.
offer-availabilityKafka, retailnetwork.offer-availability.eventsListingCreated, ListingAvailabilityChanged, ListingSuppressed, ListingRestored, CatalogItemDiscontinuedlistings and discontinued itemsBuilt. An older asOf is ignored.
node-performanceKafka, retailnetwork.node-performance.eventsNodeScorecardUpdatedscorecardsBuilt. 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 (table processed_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>.dlq at 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>.dlq with x-dlq-* headers. Shutdown never dead-letters.
  • Group ids come from <PRODUCER>_CONSUMER_GROUP with 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.

ConsumerProtocol and topicContractStatus
vendor-connectivityKafka, retailnetwork.order-sourcing.eventsFulfillmentReleasedToNode (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-transportationsameFulfillmentReleasedToNode, FulfillmentReassigned, FulfillmentLocked, FulfillmentCancelledBuilt + verified. internal/adapters/inbound/kafka/handlers.go handles these four.
delivery-promisesameFulfillmentLocked, FulfillmentShipped, FulfillmentUnsourceableBuilt + 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-orderingsameFulfillmentLocked, FulfillmentShipped, FulfillmentUnsourceable, FulfillmentCancelled, FulfillmentCancelRefusedBuilt + verified. internal/adapters/inbound/kafka/handlers.go handles these five.
seller-inboundsameFulfillmentReleasedToNode, FulfillmentCancelledBuilt + verified. internal/adapters/inbound/kafka/consumers.go (SourcingHandlers) handles these two; they feed its demand view.
customer-paymentssameFulfillmentShipped, FulfillmentCancelled, FulfillmentUnsourceableBuilt + verified. internal/adapters/inbound/kafka/handlers.go (orderSourcingHandlers) handles these three as facts on the payment authorization.
any consumersameFulfillmentConstraintRevisedPublished, no consumer found in the six clones above.
analytics read sideKafka, retailnetwork.order-sourcing.analyticsFulfillmentQueued, FulfillmentSourcingDecided, FulfillmentDeliveredConsumed 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, agentsREST GET /assignments, GET /assignments/{id}, POST /assignments/{id}/reoptimisations; MCP; A2Aapis/openapi.yaml, MCP tools, API overviewBuilt. 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_calls is 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 from vendor-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​

SituationBehaviour
Postgres down at bootMigrations 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 runtimeREST 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 downREST 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 downEvents wait in the topic; its own consumer group resumes. Nothing in this service blocks on it.
Duplicate or replayed eventThe inbox makes it a no-op; the outbox keeps the same CloudEvents id.
Late outcome of an old releasereleaseNo is not the pending one: logged and acknowledged.
Cancel after the lockRefused 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 messageDead-lettered; the partition moves on. Nothing in this repository reads or replays a .dlq topic.
Outbox row parked at OUTBOX_MAX_ATTEMPTSSkipped and logged once at ERROR; later events of the same assignment can overtake it. Re-arm it as in the Runbook.