ADR-0009 — Read-once-at-release, stamp onto WorkReleased
Status
Accepted. Decision §1 (synchronous HTTP lookup) and §2 (un-persisted
read model) superseded by
ADR-0035: the
classification now comes from a local copy of product-master's
ProductClassified events. §3–§5 still apply.
Context
A parallel effort added a ProductClassification concept to
inventory-storage: SKU-level master data tagging a SKU Hazmat, Fragile,
TemperatureSensitive, Oversized, and/or HighValue, exposed at
GET /products/{sku}/classification and written by a ClassifyProduct use
case that raises a ProductClassified domain event.
Downstream, fulfillment-execution's Task aggregate already carries a
requiredCapabilities set that a station must hold to claim a task (used
today for the pick/pack/slam process-path capability), and the
strategic direction is for it to also carry a fragile hint — both consulted
at claimNext(stationId, capabilities) time, when a station is being matched
to work. The requirement is for fulfillment-execution to have these hints
on the Task at claim time, without adding a live per-task callback into
inventory-storage — the same design already used for cpt and ref on
this service's own WorkReleased payload (see
ADR-0004 §4: "The outbound adapter
enriches WorkReleased … so the published contract is self-sufficient and no
consumer has to call back").
The question was not whether to enrich WorkReleased — that pattern is
already established — but how this service itself learns the
classification, since inventory-storage's events are this service's
upstream integration surface and Task 7
(ADR-0004) established Kafka as the
default mechanism for exactly this kind of cross-context read.
Finding: ProductClassified is not on the wire
Before building a consumer, inventory-storage's actual outbound adapter was
inspected rather than assumed. Its
internal/adapters/outbound/kafka/publisher.go carries this doc comment,
verbatim:
Only
StockReservedandReservationRevokedare part of the published integration contract … every other domain event is a local concern and is not forwarded here.
Its apis/asyncapi.yaml confirms this explicitly under "Full catalog vs.
actually published": ProductClassified is catalogued as a domain event (it
has a documented CloudEvents schema, an example payload, everything a
consumer would need to build against) but the document says outright that it
"is raised in-process only, delivered to the configured
ports.EventPublisher… and dropped by the Kafka adapter's default branch"
— and that a consumer should "not build a consumer against a catalog-only
message until it has been wired."
This matters because this service's own
ADR-0004 established Kafka projection
as the default pattern for consuming a sibling's facts
(UsableInventoryObserved from StockReserved/ReservationRevoked,
LaborPlanObserved from ShiftPlanCommitted). Following that default
blindly here would mean building an inbound consumer, a topic subscription,
and an idempotent projector for an event that never reaches
warehouse.inventory.events — a consumer with nothing to consume.
inventory-storage did, however, ship a synchronous read endpoint for the
same data (GET /products/{sku}/classification), and its own StowStock use
case already established the pattern of a synchronous outbound HTTP lookup
for a related concern: a LocationClassificationLookup port with an HTTP
Client implementation and a PermissiveLookup no-op default, selected via
LOCATION_LOOKUP_MODE=http|permissive. That is the mechanism actually
available to integrate against.
Decision
We will read a released unit's SKU classification once, synchronously,
from inventory-storage's GET /products/{sku}/classification, at the
moment ReleaseNextWork publishes WorkReleased — and stamp two derived,
OPTIONAL fields onto that event's data payload — rather than build a Kafka
projector for an event that is not actually published.
- Mechanism: synchronous outbound HTTP, mirroring inventory-storage's own
facilitylayoutadapter pattern, not a Kafka projector. A new outbound portports.ProductClassificationLookup(GetClassification(ctx, sku) (productclassificationview.ProductClassificationView, error)), a new packageinternal/adapters/outbound/productclassification/with a plainnet/httpClientand aPermissiveLookupno-op default, selected viaPRODUCT_CLASSIFICATION_MODE=http|permissive(defaultpermissive), requiringINVENTORY_STORAGE_BASE_URLinhttpmode. This is a direct structural mirror ofinventory-storage's ownLocationClassificationLookup/facilitylayoutpattern — the same integration shape this platform already uses when a synchronous read is the actual contract, just applied on the other side of the same boundary. - A new, un-persisted read model, not a projection table.
internal/domain/productclassificationview.ProductClassificationView{SKU, HandlingTags, TemperatureClass, Known}is a plain value returned by the lookup call and discarded after use — there is noprocessed_eventsrow, no Postgres table, and no idempotency concern, because nothing is being applied to persisted state. This is deliberately unlikeUsableInventoryObserved/LaborPlanObserved, which are persisted Kafka projections; conflating the two would misrepresent how fresh the data is (see the "harder" consequence below and the ubiquitous-language trap). WorkUnitcarries an optionalSKU.EnqueueWorkUnitRequestgains an optionalSKUfield (empty by default, so every existing caller keeps compiling), threaded onto theWorkUnitaggregate via a plain setter — deliberately not aNewWorkUnitconstructor parameter, so this stays additive rather than touching the aggregate's existing invariants.- The lookup and the stamp both live in the outbound Kafka adapter, next
to the existing
cpt/refenrichment ininternal/adapters/outbound/kafka/publisher.go'sdataFor. When the released unit carries a SKU, and a classification is found:"hazmat"is appended torequired_capabilitiesif the SKU is taggedHazmat;fragileis settrueif the SKU is taggedFragile. Both fields are omitted from the payload entirely — not defaulted to an explicit empty array /false— when there is nothing to say, so a consumer that already treats "absent" as "no hint" sees no difference from before this feature existed. This mirrors ADR-0004's own enrichment discipline: the translation/enrichment lives in the adapter, and the domain event (shared.WorkReleased) stays ignorant of what a downstream consumer wants. - Fail-open, always — never blocks release. An empty SKU, a
nilProductClassificationLookup(mirrorsPermissiveLookup's ownKnown=false), an unclassified SKU, or a lookup error (timeout, 5xx,inventory-storagedown) are all treated identically: no hints, andReleaseNextWorkstill succeeds and still publishes. This is a deliberate asymmetry withinventory-storage's ownStowStockplacement check, which fails closed for a Hazmat/TemperatureSensitive SKU when its lookup is unavailable (ErrLocationClassificationUnavailable, a409) — that check protects a physical placement invariant; this one only enriches an optional integration hint, and blocking a release decision on a sibling service's uptime would reintroduce exactly the coupling ADR-0004 chose Kafka to avoid in the first place.
Consequences
Easier
- fulfillment-execution's
Tasknever calls back. The hints arrive on the same event that already builds theTask, so claim-time dispatch logic (matching a station's capabilities against the task'srequiredCapabilities) never has a network dependency oninventory-storagebeing up. - No new idempotency mechanism. Because nothing is persisted, there is no
processed_eventsrow to write and nothing to double-apply on retry — unlike every Kafka-projected read model in this service. - Matches what was actually shipped. Building against
GET /products/{sku}/classificationinstead of a Kafka projector forProductClassifiedmeans this integration compiles and works againstinventory-storage's real, current contract rather than a schema that exists only in its domain-event catalogue. - Symmetric with
inventory-storage's own adapter shape. A developer who has readfacilitylayout.Client/PermissiveLookuprecognizes this adapter immediately; thePRODUCT_CLASSIFICATION_MODE=http|permissiveenv var mirrorsLOCATION_LOOKUP_MODEexactly.
Harder
- Classification drift after release is not retroactively applied. If a
SKU's classification changes after its work unit was released — say it
is reclassified
Hazmatfive minutes later — the already-publishedWorkReleasedevent, and therefore theTaskbuilt from it, does not pick up the change. This is a known and accepted gap, in the same spirit asinventory-storage's own ADR-0003 "no expiry sweeper" gap: the classification is a snapshot taken once, at release time, not a live binding. A future task could add aProductReclassified-driven correction path if this proves operationally necessary; today it is not built. - Two different freshness models for two similarly-shaped reads.
UsableInventoryObservedis continuously kept current by Kafka;ProductClassificationViewis only as fresh as the single call made at release time and is not stored anywhere in this service. A reader who assumes both work the same way will reach the wrong conclusion about staleness — the ubiquitous-language trap documents this explicitly so the question keeps getting the same answer. - A synchronous cross-service call sits on the release path. Unlike
every other integration this service performs,
ReleaseNextWork's publish step now makes a real HTTP call (inhttpmode) toinventory-storagebefore aWorkReleasedmessage reaches Kafka. The fail-open design bounds the availability risk (a slow/unavailable lookup degrades to "no hints," not to a failed release), but it does add real latency to every release whenPRODUCT_CLASSIFICATION_MODE=httpis enabled — a cost this service's core release path never paid before. required_capabilitiesis derived from a fixed, hand-picked mapping. OnlyHazmatmaps to"hazmat";Oversized/HighValue/TemperatureSensitiveare read from inventory-storage but not currently translated into anyWorkReleasedfield. If a future need requires surfacing those too, this mapping ininternal/adapters/outbound/kafka/publisher.go'sclassificationHintsis the place to extend it — documented here so it isn't rediscovered as a surprise.