0034. product-master owns product classification; this service keeps a local copy
Status
Accepted (2026-10-06). Companion of product-master ADR 0001 (bounded context) and ADR 0003 (migration); this record implements stages B and C of product-master ADR 0003 on the inventory-storage side.
- Supersedes the ownership part of
ADR 0009 ("this
service owns
ProductClassificationas source of truth"). ADR 0009's stow-time placement rules (hazmat zone, matching temperature class, fail-open/fail-closed asymmetry) stay in force unchanged. - Supersedes the publication part of
ADR 0031 ("
ClassifyProductpublishesProductClassifiedon both topics"). The wire contract of the legacy type is unchanged; only the one-shot backfill command below still emits it. - Does not change ADR 0010: the DOT segregation matrix stays here, because co-locating goods in a bin is still this context's job.
Context
product-master ADR 0001 creates a product-master bounded context as the
single source of truth for SKU-level product master data, including the
handling classification (handling tags, temperature class, DOT hazard
class). ADR 0009 had put that classification here only because no other home
existed; ADR 0009 itself calls it "a property of the product, not of any
physical holding".
StowStock still needs the classification at stow time, for two rules that
remain this context's responsibility:
- placement: a Hazmat SKU needs a hazmat-rated zone, a TemperatureSensitive SKU needs a zone with a matching temperature class (ADR 0009);
- same-bin DOT segregation against the bin's current occupants (ADR 0010).
product-master ADR 0003 sets out a strangler migration with five stages that
uses event-carried state transfer only (no shared database, no cross-context
REST). Stage A (product-master's legacy importer of this service's
ProductClassified) is product-master's own work. Stages B and C need
changes here.
Decision
Stage B: one-shot backfill command
The main binary gains a subcommand:
kubectl exec deploy/inventory-storage -- ./inventory republish-product-classifications
(the image's WORKDIR is /app and its ENTRYPOINT is ./inventory;
/app/inventory republish-product-classifications works from any directory).
- It needs only
DATABASE_URL(the pod already has it). It does not run migrations, start the HTTP server, consume Kafka or talk to the broker. - It reads every row of
product_classificationsin SKU order, in batches of 500 (keyset pagination onsku), and for each row enqueues the existing legacy CloudEventcom.warehouse.wms.inventory-storage.product.ProductClassified(dataschema urn:warehouse:inventory-storage:events:ProductClassified:v1, payload{sku, handling_tags[], temperature_class?, dot_hazard_class?}, key and subject = SKU) intooutbox_eventsfor the integration topicwarehouse.inventory.events. Each batch commits in its own transaction. The running pod's outbox relay publishes the rows; product-master's legacy importer (its ADR 0003 stage A) consumes them. - Only the integration topic is written. The analytics copy of the type
(ADR 0031) has no consumer (the projector ignores it), so the backfill does
not add rows to
warehouse.inventory.analytics. - The command prints
republished <n> product classificationsand exits 0; any database error exits non-zero. It is idempotent to re-run: every message is a full-state replacement keyed by SKU, and product-master skips anativeclassification and ignores an identical one, so a second run changes nothing downstream. A crash midway leaves the committed batches enqueued; re-running simply enqueues everything again. - The legacy encoder mapping (and its exact-JSON goldens,
internal/adapters/outbound/kafka/product_classified_test.go) stays, for this command only. The normal write path no longer raises the event.
Stage C: cutover of write authority
PUT /products/{sku}/classificationreturns410 Gonewith problem typehttps://errors.inventory-storage.warehouse-systems.dev/classification-movedand a detail naming product-master'sPUT /products/{sku}/classification. The request body is not read. TheClassifyProductuse case is removed (it had no MCP tool).- Local copy consumer. A new inbound Kafka consumer reads
product-master's topic
warehouse.product-master.eventswith a stable consumer group taken from envPRODUCT_MASTER_CONSUMER_GROUP. When the variable is unset the consumer is not started (the local copy then only holds the legacy rows). It requiresDATABASE_URLandKAFKA_BROKERS; boot fails if the group is set without them.- It acts only on the full type
com.warehouse.wms.product-master.product.ProductClassified, payload{sku, handling_tags[], temperature_class?, dot_hazard_class?, classification_source, version}; every other type on the topic is committed past untouched. - Use case
ApplyProductClassificationclaims the CloudEventsidinprocessed_events(consumerproduct-master-classification) and upsertsproduct_classificationsin oneUnitOfWork. The upsert applies only when the incomingversionis greater than the stored one (a missing row is inserted). A duplicateidor a staleversionis a no-op that still commits the offset. - It raises no domain event: nothing reaches the outbox, so there is no publish loop between the two contexts.
- At-least-once rules:
FetchMessage+CommitMessagesonly after the handler settles; a transient (database) error retries the same message with capped backoff; a message that is not a valid CloudEvent, has an undecodable payload or breaks the classification invariants is logged and committed past.
- It acts only on the full type
- Migration
0033_product_master_local_copyadds toproduct_classifications:version BIGINT NOT NULL DEFAULT 0andclassification_source TEXT NOT NULL DEFAULT 'inventory-storage'. Legacy rows keep version 0, so the first product-master version (1 or more) always wins; applied rows store product-master'sclassification_source(nativeorlegacy-import). It also createsprocessed_events (consumer, event_id, processed_at)with primary key(consumer, event_id); this repository had no inbound dedupe table in the OLTP database (the transfer consumer dedupes on its own ledger'stransfer_line_id). StowStockis unchanged. It reads the sameports.ProductClassificationRepo.FindBySKUas before; the table is now fed by the consumer instead of a REST write.GET /products/{sku}/classificationstays, served from the local copy, and is markeddeprecated: trueinapis/openapi.yaml. It was removed at product-master ADR 0003 stage E (2026-10-17).
Stage E (executed 2026-10-17)
The deprecated PUT/GET endpoints, the backfill command and the legacy
encoder mapping were removed after the cluster was verified: every
classification row of product_classifications had a product-master product
(six SKUs the importer missed were backfilled through the product-master
REST API first). This file otherwise documents stages A-D as run.
Consequences
- Classifications become eventually consistent here: a SKU classified in product-master moments before its first stow may still stow as unclassified (fail-open, ADR 0009). That is the same window any cached reader already had.
- Between deployment and the first run of the backfill, product-master knows no legacy classification; the runbook in product-master ADR 0003 runs the backfill right after product-master is ready.
- Operators classify SKUs in product-master only. A client still calling
this service's
PUTgets a 410 with the new address instead of a silent write that product-master would never see. - One more consumer group to operate (
PRODUCT_MASTER_CONSUMER_GROUP). ProductClassifiedis no longer published on the normal write path, so any sibling that had started to read it fromwarehouse.inventory.eventsmust read product-master's topic instead (none had, per ADR 0031).