SR-006 — Scalable Search Product System Requirements

By Engineering Team•September 27, 2026•4 min read

Metadata

Field Value
Project Name Scalable Search Product
Document ID SR-006
Author Engineering Team
Status Draft
Traces to BRD-006

This document derives the concrete requirements behind BRD-006 from the current implementation across shop-service, search-service, and ui-application. It does not restate SR-005’s FR-14 (Search Dispatch by Section Type) or NFR-05 (One-Directional Search Dependency) — those already cover the searchProducts Strategy-pattern dispatch and the one-directional shop-service → search-service gRPC call; this document covers what happens on either side of that dispatch for the global/keyword search path specifically.

1. Functional Requirements (FR)

Keyword search and ranking

  • FR-01 (Free-Text Query Parameter): shop-service’s SearchProductsFilterInput GraphQL type and search-service’s SearchProducts gRPC contract MUST both carry an optional query/Query string field. An empty or whitespace-only query MUST be treated as “no text filter” (matches everything, subject to the other filters), not “match nothing.”
  • FR-02 (Atlas Search Full-Text Ranking): search-service MUST score the query field via a MongoDB Atlas Search $search aggregation stage (index product_search_index) using a compound operator — a mandatory tenant/status filter clause, conditional must clauses for category/gender/variant/price/discount filters, and a conditional should clause block scoring title (boosted, fuzzy), tags, category.name, and description.
  • FR-03 (Typo Tolerance): The title text clause MUST apply Atlas Search fuzzy matching (maxEdits: 1, prefixLength: 2) so a one-character typo or transposition still matches, satisfying BRD-006’s BR-03.
  • FR-04 (ID-Only Search Result, Hydrated by the Caller): search-service’s SearchProductIDs MUST return only matched product IDs (plus a total count via a $facet count branch) — it MUST NOT return product detail, price, or stock fields itself. The calling strategy is responsible for hydrating those IDs into full Product records. (This corrects a factual error in search-service’s own “no request-time join needed” claim — see Technical-Debt-00006.)
  • FR-05 (Request-Time Hydration Join): shop-service’s GlobalSearchStrategy MUST, after receiving matched IDs from search-service, call product-catalog’s GetProductDetailsByIDs and inventory-service’s GetProductPricing (both gRPC) to hydrate the matched IDs into displayable Product records, dropping any ID with no detail or pricing counterpart rather than failing the whole request.
  • FR-06 (Offset/Limit Pagination): searchProducts MUST accept offset/limit parameters, and search-service’s aggregation pipeline MUST apply them via $skip/$limit inside the $facet data branch. (Gap — offset-based pagination has a known scaling limit at deep pages; tracked in Technical-Debt-00006.)

Typeahead / suggestions

  • FR-07 (Suggest Endpoint, Decoupled from Results): search-service MUST expose a REST suggest endpoint (GET /client/api/v1/product/full-search, served by SuggestProducts) that ui-application calls directly via Dio — independent of the GraphQL searchProducts query used for the results grid. Typing MUST NOT trigger searchProducts; only a dropdown-row tap or a submitted query MUST trigger it.
  • FR-08 (Debounced, Length-Gated Suggest Calls): The Flutter client MUST debounce keystroke-driven suggest calls by 350ms and MUST NOT issue a suggest call for a query shorter than 3 characters.
  • FR-09 (Two Suggestion Kinds): The suggest response MUST distinguish product-match suggestions from demographic-scoped keyword suggestions (e.g. “dress for Women”), the latter grouped by product_search.target_demographics via a $unwind+$group aggregation, not by category.id.
  • FR-10 (Keyword Pick Sets Gender Filter): Selecting a demographic-scoped keyword suggestion MUST auto-apply that demographic as a genders filter value on the subsequent searchProducts call, folded into the same genders parameter the structured filter sheet uses — no separate field.

Filter schema (independent of the search index)

  • FR-11 (Filter Schema Endpoint): shop-service MUST expose GET /api/v1/filter/schema, sourced from its own admin-curated category_mapping collection joined against product-catalog’s CategoryQueryService.GetCategoriesByIDs (gRPC) and shop-service’s own category-group image lookup — independent of search-service’s index. Search filtering and the filter schema’s category/attribute options MUST remain consistent even though they are served by two different services.
  • FR-12 (Schema-Driven Filter UI, No Hardcoded Options): The Flutter filter sheet MUST render every option (product-type groups, per-group variant attributes, gender list, price/discount slider bounds, sort options) from the live schema response — no hardcoded fallback list for any of these fields.
  • FR-13 (Variant Attribute Filter by Active Group’s Own Naming): A selected size/color filter value MUST be sent to searchProducts using the active filter group’s own variant attribute name (e.g. “Size” for Clothes, “Frame Size” for Watches), not a hardcoded attribute name string.

Catalog-to-search synchronization (async index sync)

  • FR-14 (Product Lifecycle Event Ingestion): search-service MUST subscribe to product-catalog’s product-event Pub/Sub topic (own subscription, distinct from any other consumer of that topic) and, on each event, map the payload’s EventType (product created, basic info/specification updated, cloned, published, archived, or deleted) to an upsert or status change on the corresponding product_search document — never requiring a tenant to take a separate manual step to make a new or edited product findable, satisfying BRD-006’s BR-05.
  • FR-15 (Inventory Price/Stock Summary Ingestion): search-service MUST subscribe to inventory-service’s inventory-search Pub/Sub topic and update the matching product_search document’s coarse inventory.price_min/price_max/total_stock/is_available block from the event payload.
  • FR-16 (Ordered Stock-Status Ingestion): search-service MUST subscribe, with Pub/Sub message ordering enabled and keyed by product ID, to inventory-service’s stock-balance-status-changed topic, and update the matching SKU’s is_in_stock/stock_status fields inside product_search.skus[]. Ordering MUST be enabled on this stream specifically because an out-of-order pair of stock-status flips for the same product (e.g. an in-stock event overwriting a later out-of-stock one) would leave product_search showing a shopper stock availability that’s actually wrong, not just stale.
  • FR-17 (SKU Compliance/Pricing Ingestion, Shared Topic, Status-Filtered): search-service MUST subscribe, via its own independent subscription, to the same sku-compliance-pricing-upserted Pub/Sub topic that product-catalog’s publish-readiness gate already consumes (see ADR-00005) — not a second, duplicate topic — and MUST process only events whose status field is "COMPLETED", discarding the same operation’s earlier "PROCESSING"/"FAILED" events on this topic, to populate per-SKU pricing/attribute rows in product_search.skus[].
  • FR-18 (Independent, Per-Stream Consistency): FR-14 through FR-17 are four independent event streams, each with its own topic/subscription and payload shape — a delayed or failed event on one stream MUST NOT block or delay processing of the other three; search-service has no single unified “catalog changed” event.

2. Non-Functional Requirements (NFR)

  • NFR-01 (Index-Backed, Not Table-Scanned): All keyword and filter matching MUST run against the Atlas Search index (product_search_index), never an unindexed collection scan, so query latency does not grow linearly with total catalog size. (Rationale for choosing Atlas Search itself over a standalone search engine: ADR-00007.)
  • NFR-02 (Tenant Isolation via Shared Index): Every $search query MUST include a mandatory tenant-scoping clause in its compound.filter, so a single shared index serves every tenant without a shopper ever seeing another tenant’s products. (Gap — a shared index’s scaling ceiling as tenant count grows is not yet load-tested; tracked in Technical-Debt-00006.)
  • NFR-03 (Bounded Catalog-to-Search Freshness): A product/price/stock change published by product-catalog/inventory-service (FR-14–FR-17) MUST reach product_search (and therefore become searchable) within a bounded eventual-consistency window, the same accepted trade-off documented for event-driven sync generally in ADR-00005. (Correction: this NFR previously stated that search-service “consumes the identical event sources” as ADR-00005’s five step-completion events. That’s inaccurate — ADR-00005’s five events flow only to product-catalog’s publish-readiness gate. Three of search-service’s four sync streams (FR-14, FR-15, FR-16) are entirely separate topics ADR-00005 doesn’t cover; only one (FR-17, sku-compliance-pricing-upserted) is a topic ADR-00005’s product-catalog subscriber also consumes, via its own independent subscription. See ADR-00017 and Technical-Debt-00006, TD-05.)
  • NFR-06 (Best-Effort Delivery, Errors Never Block the Triggering Request): None of the four publishers behind FR-14–FR-17 MUST fail or roll back the admin-facing write that triggered them if the Pub/Sub publish itself fails — a publish error is logged, never surfaced to the operator, and never blocks product-catalog/inventory-service’s own response. (Gap — this makes a publish failure silently invisible to anyone except someone reading logs, with no re-drive mechanism beyond Pub/Sub’s own message retry; tracked in Technical-Debt-00006.)
  • NFR-04 (No Search-Path Server-Side Cache): Neither shop-service’s searchProducts gRPC call nor search-service’s Atlas Search query currently sits behind a server-side cache. (Gap — tracked in Technical-Debt-00006.)
  • NFR-05 (Suggest Latency Bound by Debounce): The 350ms debounce and 3-character minimum on suggest calls (FR-08) MUST be the primary mechanism keeping suggest-call volume proportional to deliberate typing, not to every keystroke, so suggest-path load scales with shopper count rather than with keystroke count.