0003. Kafka choreography consumer of fulfillment-execution, no REST dependency
Status
Accepted. Established with the initial implementation of this bounded context.
Envelope superseded by ADR-0021. The flat envelope (
event_id/event_type/occurred_at) described below is retired: every message is now a CloudEvents 1.0 event. The rest of this decision stands.
Context
This service's core job — scoring a completed task against a standard —
needs three facts about that completion: AssociateId, TaskType, and
DurationSeconds. All three conceptually belong to fulfillment-execution
(Task lifecycle) or workforce-management (associate identity). Two
integration shapes were available:
- Synchronous HTTP calls to
fulfillment-executionand/orworkforce-managementat scoring time — the shapeorder-managementoriginally used forinventory-storage/wes-work-planningbefore its own choreographed-release redesign (see that repo's ADR 0005). - Asynchronous Kafka consumption of an event
fulfillment-executionalready publishes, matching the provenwes-work-planning←fulfillment-execution/order-managementconsumer pattern (wes-work-planning's ownRecordCompletion/EnqueueWorkUnitconsumers).
Forces favoring option 2:
- This service's entire job IS reacting to a completed task — a fact that already happened. There is no synchronous request/response this service needs to make; it never asks fulfillment-execution to do anything, it only observes what already occurred. That is the textbook shape for choreography over orchestration.
fulfillment-executionalready publishesTaskCompletedonwarehouse.fulfillment.events, and the siblingfeature/labor-performance-hooksPR in that repo (verified this session against its actualinternal/adapters/outbound/kafka/publisher.go) enriches that SAME event withAssociateIdandDurationSeconds— no new topic, no new publisher, no synchronous endpoint had to be built on that side at all. This build is 100% additive fromfulfillment-execution's point of view.- A synchronous HTTP dependency would invert the coupling direction this
fleet's DDD reference docs establish.
fulfillment-executionis Core; this context is Supporting. Making Core block on a Supporting-context HTTP call (or, worse, having Supporting poll/call Core synchronously at scoring time, adding latency and a new failure mode to every task completion) is exactly the anti-patternwes-work-planning's own choreographed-release migration eliminated fororder-management→wes-work-planning. workforce-management's own boundary already forbids the join this service might otherwise be tempted to make. That context "never links an associate to a specific task" (see ADR 0002), so there is no synchronous endpoint on that side to call in the first place —AssociateIdmust come from wherever it is already resolved, which isfulfillment-execution's station-occupant lookup at publish time.
Decision
This service is a pure Kafka consumer. It:
- Subscribes to
warehouse.fulfillment.events— the SAME shared, fan-out topicwes-work-planningalready consumes from — under its own consumer group (labor-performanceby default). - Acts only on
event_type == "TaskCompleted"; every other event type on that shared topic is silently skipped, mirroringwes-work-planning's own consumer's skip-unrecognized-event-type behavior. - MUST NOT import any Go package from
fulfillment-executionorworkforce-management— it is a separate Go module in a separate repository, and the inbound Kafka adapter'staskCompletedDatastruct is this context's own private mirror of the wire shape, not a shared type. - MUST NOT call either sibling context synchronously over HTTP, ever — it has zero REST dependency on either, matching the "everything it needs is already on the Kafka event" design.
- Exposes its own REST API (
POST /standards,GET /standards/{taskType},GET /associates/{associateId}/scorecard,GET /task-types/{taskType}/performance) as its OWN Open Host Service, symmetric with every other context in the fleet — this is this context's outbound surface, not an inbound dependency on anyone else.
Idempotency is keyed on the Kafka message's event_id, not TaskId —
a TaskId could in principle be reused after a very long time, so the
ProcessedEvents gate (mirroring workforce-management's
internal/application/ports.ProcessedEvents idempotency-gate pattern)
uses the envelope's own de-duplication key. Unlike workforce-management's
use of that pattern — which gates only an additive analytics
side-projection — here it gates the entire OLTP write path, since
consuming TaskCompleted IS this service's whole job, not a side effect
of it.
A wire-contract gap, closed: fulfillment-execution's
TaskCompletedData originally did not carry a task_type field, so this
service resolved TaskType as "" (unclassified) for every event — see
shared.ParseTaskTypeLenient's doc comment. fulfillment-execution's own
ADR-0023 added task_type to that payload; this service's consumer
(consumer.go) now reads it directly (data.TaskType, handed through
ParseTaskTypeLenient unchanged — an unrecognized/absent value still
degrades to ""), closing the gap recorded here. See README.md's "Known
gaps" section and ADR-0014's own note on the same closure.
Consequences
Easier
- No new failure mode on the fulfillment-execution hot path. A task completion never blocks, retries, or slows down waiting on this service; if this service is down, messages queue in Kafka and are processed on recovery, at-least-once.
- This service can be deployed, scaled, and even go down independently
without affecting
fulfillment-execution's orworkforce-management's own availability — the defining benefit of choreography over orchestration. - Testing is a fake-reader unit test, not a live-broker integration
test, for the common case (see
consumer_test.go), with a real broker reserved for the separate, build-taggedconsumer_integration_test.go.
Harder
- This service cannot backfill/repair TaskType for already-recorded,
unclassified rows without either a fulfillment-execution enrichment
landing (adding
task_typeto the wire) or a manual reprocessing pass — there is no synchronous fallback lookup to fill the gap, by design. - A redelivered-but-slightly-different message (e.g. a genuine data
correction re-published under a NEW
event_idfor the sameTaskId) would be recorded as a second row, sinceTaskIdis treated purely as an opaque foreign reference, not a repository key. This is accepted as consistent withTaskPerformancebeing described as "immutable once recorded" — a real correction from the source of truth is a new fact, not an edit of the old one.