ADR-00017 — Independent Pub/Sub Streams for Catalog-to-Search Synchronization
Context
search-service maintains its own denormalized product_search collection so the mobile storefront’s keyword search never has to fan out across product-catalog and inventory-service at query time (see ADR-00007). That collection needs four different kinds of upstream data — product descriptive fields, price/stock summary, ordered stock-status flips, and per-SKU compliance/pricing — and none of that data lives in one place today: product lifecycle fields live in product-catalog, everything else in inventory-service.
ADR-00005 already established an event-driven pattern for a different consumer — product-catalog’s own publish-readiness gate, which subscribes to inventory-service’s five step-completion events. This ADR covers the separate decision of how search-service gets fed, which is not the same event set and not the same purpose, even though one topic ends up genuinely shared between the two (see Decision, Option 1, below).
Decision Drivers
- SR-006 FR-14 through FR-18 (the four sync streams and their independence requirement) and NFR-03 (bounded freshness), NFR-06 (best-effort delivery, never blocks the triggering request).
search-servicemust not become a synchronous dependency ofproduct-catalog’s orinventory-service’s own write paths — an admin saving a product or a SKU’s pricing must never wait on, or fail because of,search-service’s availability.- Two of the four data kinds (SKU-level stock status, SKU-level compliance/pricing) can be misapplied if processed out of order for the same product/transaction — a stale event overwriting a newer one leaves
product_searchactively wrong, not just late. - Avoid re-deriving a translation/aggregation layer that isn’t needed by any current requirement.
Options Considered
Option 1 (Chosen): Four independent, best-effort Pub/Sub streams, one per producer-owned event type
search-service runs four separate subscriptions, each mapped to its own handler:
| # | Topic | Publisher | Ordering | Subscription |
|---|---|---|---|---|
| 1 | product.catalog.updated |
product-catalog (ProductSearchEventPublisher) |
None | product.catalog.updated-search-service |
| 2 | inventory-search-event |
inventory-service (InventorySearchEventPublisher) |
None | inventory-search-event-search-service |
| 3 | stock-balance-status-changed |
inventory-service (StockStatusChangedEventPublisher) |
Yes — keyed by product ID | stock-balance-status-changed-search-service |
| 4 | sku-compliance-pricing-upserted |
inventory-service (SkuCompliancePricingUpsertedEventPublisher) |
Yes — keyed by transaction ID | sku-compliance-pricing-upserted-search-service |
Stream 4 reuses the exact same topic product-catalog’s publish-readiness gate already subscribes to (ADR-00005) — via a second, independent subscription, not a second topic. inventory-service publishes the event once; Pub/Sub fans it out to both consumers, each with their own cursor/ack state. search-service’s handler additionally filters to status == "COMPLETED" only, discarding the same operation’s PROCESSING/FAILED events on that topic, since only a completed upsert has a finished pricing row worth indexing.
This mirrors the same per-step, independent-event shape ADR-00005 already established (one topic per producer-owned fact, no consumer waits on another consumer’s processing) — just for a different consumer and a different purpose. Each publisher call is fire-and-forget or best-effort-inline (never blocking the admin request that triggered it — see SR-006 NFR-06), and each of search-service’s four subscriptions processes independently, so a delayed or failed message on one stream never blocks the other three (SR-006 FR-18).
Option 2 (Rejected): Single unified “catalog changed” event / CDC
Introduce one canonical event type (or a change-data-capture pipeline off product-catalog’s Mongo and inventory-service’s Postgres) that both product-catalog’s readiness gate and search-service consume identically.
Rejected because:
- It requires redesigning every existing publisher in both
product-catalogandinventory-service— five wizard-step publishers already exist and work, built around per-step boundaries (ADR-00005), not around search’s own field needs. - It adds a translation/normalization layer whose only justification would be a future requirement that doesn’t exist yet — no current consumer needs a unified shape, and
search-service’s own four field groups (descriptive, price/stock summary, per-SKU stock status, per-SKU pricing) map naturally onto four distinct upstream events, not one. - CDC would couple
search-service’s freshness to two different databases’ change-stream/WAL mechanics in two different languages, a materially larger operational surface than four Pub/Sub subscriptions.
Option 3 (Rejected): Synchronous polling or request-time lookback
search-service polls product-catalog/inventory-service on an interval, or performs a lookback query against both at read time to fill in anything not yet indexed.
Rejected because:
- Polling reintroduces the coupling event-driven sync exists to avoid —
search-service’s freshness would depend on both upstream services’ availability and load, the exact trade-off ADR-00005’s own Option 2 rejection (synchronous validation call at publish time) already rejected for a different pair of services in this platform. - A request-time lookback defeats the purpose of a denormalized index (see ADR-00007) — it would reintroduce the very request-time join
search-serviceexists to avoid for the majority of fields, even ifshop-service’sGlobalSearchStrategystill performs one narrower gRPC hydration join today (tracked separately as Technical-Debt-00006, TD-04).
Decision
Option 1. Four independent Pub/Sub streams, each scoped to one producer-owned event type, with the fourth stream reusing sku-compliance-pricing-upserted via a second, independent subscription rather than inventory-service publishing the same data twice under two topic names.
Ordering-key rationale: only streams 3 and 4 enable Pub/Sub message ordering. Stock-status (stream 3) and compliance/pricing (stream 4) both represent a state that can be actively misread if an older event is applied after a newer one for the same product/transaction — e.g. an in-stock flip overwriting a later out-of-stock flip. Product lifecycle events (stream 1) and the inventory price/stock summary (stream 2) don’t carry this same risk in their current field shape — each event on those streams is closer to a full snapshot than a delta, so a later event always supersedes an earlier one regardless of arrival order, making ordering unnecessary overhead for those two.
Consequences
search-servicenever blocks, and is never blocked by,product-catalog’s orinventory-service’s write paths — consistent with SR-006 NFR-06.- A publish failure on any of the four streams is currently logged only, with no operator-visible signal or re-drive mechanism beyond Pub/Sub’s own retry — tracked as Technical-Debt-00006, TD-06.
- The four streams are independently evolvable — a fifth data need (e.g. a future recommendation signal) can be added as a fifth stream without touching the other four, the same modularity ADR-00005 established for
product-catalog’s own five step events. - Two different consumers (
product-catalog’s readiness gate,search-service’s indexer) now depend on the samesku-compliance-pricing-upsertedtopic for two different purposes — a schema change to that event’s payload must consider both consumers, not just one. This coupling is judged acceptable today because both consumers need the same underlying fact (a SKU’s pricing was upserted); it is flagged here so a future payload change doesn’t silently break one of the two subscribers.
Related Documents
- BRD-006 — Scalable Search Product
- SR-006 — Scalable Search Product System Requirements (FR-14–FR-18, NFR-03, NFR-06)
- ADR-00005 — Event-Driven Catalog Synchronization
- ADR-00007 — MongoDB Atlas Search for Product Search
- Architecture: Scalable Search Product
- Technical Debt — Scalable Search Product Gaps
- search-service
- product-catalog
- inventory-service