0035. Product classification from a local copy of product-master events
Status
Accepted (2026-10-06). Supersedes the live-lookup part of
ADR-0009
(its Decision §1 "synchronous outbound HTTP" and §2 "un-persisted read
model"); ADR-0009 §3–§5 (SKU on WorkUnit, the stamp in the outbound Kafka
adapter, fail-open) stay in force. Also retires the product-classification
breaker of ADR-0023
(the travel-distance breaker is unchanged).
Amended by ADR-0044: permissive and the in-memory copy no longer exist; the mode defaults to kafka.
Companion decisions: product-master ADR 0001 (product-master owns SKU-level product master data) and ADR 0003 stage D (downstream readers move to local copies), inventory-storage ADR 0034 (hand-over of classification to product-master).
Context
ADR-0009 read a released unit's classification once, synchronously, from
inventory-storage's GET /products/{sku}/classification, because
inventory-storage did not publish ProductClassified. Two things changed:
- The source of truth moved. Classification now belongs to the new
product-masterbounded context (product-master ADR 0001). inventory-storage hands it over (its ADR 0034): its write endpoint is retired and itsGETis deprecated until it is removed (product-master ADR 0003, stage E). - The fact is now on the wire. product-master publishes
com.warehouse.wms.product-master.product.ProductClassifiedonwarehouse.product-master.eventsthrough its transactional outbox: Kafka key and CloudEventssubject= the SKU,datais a full-state replacement of the classification carrying the aggregateversion({"sku","handling_tags","temperature_class"?,"dot_hazard_class"?,"classification_source","version"}). product-master ADR 0001 forbids service-to-service lookups against it: the RESTGETendpoints exist for operators, the console and agents.
The reason ADR-0009 gave for not projecting ("there is nothing to consume") no longer holds, and the HTTP client would keep a runtime dependency on an endpoint that is being decommissioned.
Decision
We replace the HTTP adapter behind the unchanged
ports.ProductClassificationLookup port with a local copy of
product-master's classification, fed by Kafka. The domain, the use cases
that release work, and the WorkReleased payload are unchanged.
- Local copy table. Migration
0012addsproduct_classification_copy (sku TEXT PRIMARY KEY, handling_tags TEXT[], temperature_class TEXT NULL, dot_hazard_class SMALLINT NULL, version BIGINT, updated_at TIMESTAMPTZ). One row per SKU; there is no "unclassify" event in v1, so rows are never deleted. - Consumer. A dedicated inbound consumer
(
internal/adapters/inbound/kafka/product_classification_consumer.go) readswarehouse.product-master.eventsunder a stable consumer group read fromPRODUCT_CLASSIFICATION_CONSUMER_GROUP(never a literal; the copy is shared state in Postgres, so every replica shares the group and splits the partitions; a new group starts from the earliest offset so the copy fills from history). It acts on the full typecom.warehouse.wms.product-master.product.ProductClassifiedonly and ignores every other type on the topic (ProductRegistered,ProductDescriptionChanged,ProductDimensionsDeclared,ProductMeasured). - Exactly-once effect, at-least-once delivery. A new
ObserveProductClassificationuse case claims the CloudEventsidin the existingprocessed_eventstable and applies the version-guarded upsert in oneUnitOfWorkthrough the sameonceAtomicallyprimitive every other inbound event uses (ADR-0028). The upsert inserts a missing SKU and overwrites an existing row only when the incomingversionis greater than the stored one; an equal or older version (replay, out-of-order redelivery) is a no-op that still records theid. - Error handling. A message that is not a valid CloudEvent, or a
ProductClassifiedwhosedatacannot be decoded or lacksskuor aversion≥ 1, is deterministic poison: logged at WARN with topic/partition/offset and committed past (no DLQ: nothing about it can ever succeed). Any other failure (database, transaction) is transient: the same message is retried with capped exponential backoff until it succeeds or the process stops, and the offset is committed only after success (FetchMessage+CommitMessages). A stalled partition is loud (ERROR per attempt) rather than silently skipping a classification. - Lookup.
GetClassificationreads the copy and maps it to exactly what the HTTP client returned:Known=truewithHandlingTagsandTemperatureClassfor a stored SKU,Known=falsefor an unknown SKU, andKnown=falsewith a nil error for any read failure (ADR-0009 §5, fail-open: classification never blocks or delays a release). Because the outbox encoder calls it inside the release transaction, the read runs in a savepoint, so a failed read can never abort the release transaction.dot_hazard_classis stored but not surfaced: the view and theWorkReleasedmapping (Hazmat→"hazmat",Fragile→fragile) are unchanged. - Modes.
PRODUCT_CLASSIFICATION_MODEbecomeskafka|permissive(defaultpermissive, unchanged).httpis removed and rejected at boot with an error naming the allowed values, as is any other value, so a stale deployment fails loudly instead of silently degrading.cmd/wes, modekafka: requiresKAFKA_BROKERSandPRODUCT_CLASSIFICATION_CONSUMER_GROUP(either missing is a boot error); wires the Postgres copy (or an in-memory copy whenDATABASE_URLis unset) as the lookup and starts the consumer. On shutdown it is stopped and drained right after the main integration consumer, before the HTTP server and the pool close.cmd/mcp, modekafka: never starts a consumer and does not read the group variable. WithDATABASE_URLit reads the sameproduct_classification_copytable read-only (cmd/wes owns the migration and the writes); without a database it uses the permissive lookup and logs that it did.permissivein either binary: unchanged no-op,Known=false.
- Removed. The
internal/adapters/outbound/productclassificationHTTP client, its circuit breaker and retry, their tests, and every use ofINVENTORY_STORAGE_BASE_URL(classification was its only use in this repo). The permissive lookup moves to the newinternal/adapters/outbound/productclassificationcopypackage, next to the Postgres and in-memory copies.
Consequences
- No synchronous cross-service call on the release path. The latency and availability coupling ADR-0009 accepted ("harder", third bullet) is gone; the lookup is a primary-key read in this service's own database.
- Eventual consistency. A classification reaches this context after product-master's outbox relay and this consumer have both run (normally well under a second; longer while either is down or lagging). A SKU classified moments before its first release can be released without its hints: the same outcome as an unknown SKU today (fail-open, no hints), which ADR-0009 already accepted. Released work is still not re-stamped when a classification changes later (ADR-0009, "harder", first bullet).
- Empty copy until the backfill. Until product-master has imported and re-published the legacy classifications (product-master ADR 0003 stages A and B), older SKUs are unknown here and release without hints. The runbook runs the backfill right after product-master is ready.
- Deployment change required. An environment still setting
PRODUCT_CLASSIFICATION_MODE=http(warehouse-infra did, for this service) no longer boots: it must switch tokafkaand setPRODUCT_CLASSIFICATION_CONSUMER_GROUP, or drop the variable to getpermissive.INVENTORY_STORAGE_BASE_URLis no longer read. - In-memory runs. Without
DATABASE_URLthe copy lives only as long as the process. With a stable group a restart resumes after the committed offsets and the copy starts empty, so a local in-memory run should use a freshPRODUCT_CLASSIFICATION_CONSUMER_GROUPper run to replay the topic. - One more consumer to operate. Its lag is the staleness of the copy; the existing Kafka consumer-lag dashboards apply to the new group.
- Contract.
apis/asyncapi.yamldeclares the consumed channelwarehouse.product-master.eventswith theProductClassifiedmessage; ADR-0027's consumed-type list gains the type. No published event, REST endpoint or MCP tool changes.