ADR 0003: Migrating classification ownership from inventory-storage
Status
Accepted (2026-10-06). Companion decisions: inventory-storage ADR 0034 (hand-over) and one ADR in each of order-management, wes-work-planning and fulfillment-execution (local copy instead of live lookup).
Context
ADR 0001 moves ProductClassification out of inventory-storage. Existing
classifications live only in inventory-storage's product_classifications
table. inventory-storage started publishing
com.warehouse.wms.inventory-storage.product.ProductClassified on
warehouse.inventory.events on 2026-10-06 (its ADR 0031) but did not backfill
older rows onto the topic. Three services read classifications live over REST.
The migration must not lose a classification, must never let two contexts both accept writes for the same fact at the same time, and must not create a publish loop between the two contexts.
Decision
A strangler migration in five stages, using event-carried state transfer only (no shared database access, no cross-context REST calls).
Stage A: product-master runs a legacy importer
product-master consumes warehouse.inventory.events with a stable consumer
group from env LEGACY_IMPORT_CONSUMER_GROUP (unset = importer not started).
It acts only on the full type
com.warehouse.wms.inventory-storage.product.ProductClassified, ignores every
other type, dedupes on the CloudEvents id in the same transaction as the
effect, and commits the offset afterwards. For each message, use case
ImportLegacyClassification:
- SKU unknown: register the product (empty description) and set the
classification with
classificationSource=legacy-import. - SKU known, classification authored in product-master
(
classificationSource=native): skip. product-master is the authority; a legacy message never overwrites a native decision. - SKU known, no classification or a legacy one: replace it, unless the incoming classification is identical (then no change, no version bump, no event).
Every accepted import raises product-master's own events
(ProductRegistered, ProductClassified) through the outbox, so
downstream copies fill from one topic only.
Stage B: backfill
inventory-storage gains a one-shot command that re-emits every row of
product_classifications as its existing ProductClassified event through its
outbox (details in inventory-storage ADR 0034). The payload is a full-state
replacement, so running it twice is harmless. The importer above turns it into
product-master data.
Stage C: cutover of write authority (inventory-storage)
PUT /products/{sku}/classificationon inventory-storage returns410 Gonewith problem typeclassification-moved, naming product-master's endpoint.- inventory-storage's write path stops raising
ProductClassified(theClassifyProductuse case is removed). The only remaining emitter of the legacy type is the one-shot backfill command of stage B, an explicit operator action, and both disappear at stage E. - inventory-storage consumes product-master's
ProductClassifiedand upserts its existingproduct_classificationstable, guarded byversion. That table becomes a local copy that StowStock reads exactly as before. - inventory-storage's
GET /products/{sku}/classificationkeeps working from the local copy and is marked deprecated until stage E.
Applying product-master's events raises no event in inventory-storage, so
there is no loop: product-master -> inventory-storage is one-way after stage
C. Running the backfill again after the cutover is harmless: every
re-emitted classification is either native in product-master (skipped) or
identical to what it already holds (no change).
Stage D: downstream readers move to local copies
order-management, wes-work-planning and fulfillment-execution keep their
ProductClassificationLookup port and swap only the adapter: a Kafka consumer
of warehouse.product-master.events writes a local Postgres copy, and the
lookup reads it. PRODUCT_CLASSIFICATION_MODE becomes kafka|permissive;
http is removed and rejected at boot, so a stale deployment fails loudly
instead of silently degrading to permissive.
Stage E: decommission (after the cluster is verified)
Remove inventory-storage's deprecated GET endpoint and its backfill command,
remove product-master's legacy importer and LEGACY_IMPORT_CONSUMER_GROUP,
and mark the inventory-storage ProductClassified type retired in
warehouse-docs.
EXECUTED 2026-10-17: every classification row of
inventory_storage.product_classifications was verified present in
product-master first (six SKUs missed by the importer were backfilled through
the product-master REST API), then the importer, its chart value and the
consumer-group env were removed here; inventory-storage's backfill command
and legacy publisher go in its own PR; the warehouse-docs retirement note
follows with the deploy.
Runbook (first deployment)
- Deploy product-master with
LEGACY_IMPORT_CONSUMER_GROUPset, then inventory-storage (stage C) and the readers (stage D). - Run inventory-storage's backfill command once.
- Check that the number of classified products in product-master
(
GET /products?classified=true, counting all pages) equals the row count of inventory-storage'sproduct_classifications. - Probe asymmetrically: a Hazmat SKU stows into a hazmat zone (201) and is rejected from a non-hazmat zone (409).
Between steps 1 and 2, readers see no classification for older SKUs and apply their existing unknown-SKU behaviour (fail-open for enrichment). Run step 2 right after product-master is ready, before routing traffic.
Consequences
- Every downstream copy is fed from one producer and one topic; the importer and the legacy type disappear at stage E.
classificationSourceis a migration artefact. After stage E every new write isnative; existinglegacy-importrows stay labelled, which tells stewards which classifications were never reviewed in product-master.