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’sSearchProductsFilterInputGraphQL type andsearch-service’sSearchProductsgRPC contract MUST both carry an optionalquery/Querystring 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-serviceMUST score thequeryfield via a MongoDB Atlas Search$searchaggregation stage (indexproduct_search_index) using acompoundoperator — a mandatory tenant/statusfilterclause, conditionalmustclauses for category/gender/variant/price/discount filters, and a conditionalshouldclause block scoringtitle(boosted, fuzzy),tags,category.name, anddescription. - FR-03 (Typo Tolerance): The
titletext clause MUST apply Atlas Searchfuzzymatching (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’sSearchProductIDsMUST return only matched product IDs (plus a total count via a$facetcount branch) — it MUST NOT return product detail, price, or stock fields itself. The calling strategy is responsible for hydrating those IDs into fullProductrecords. (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’sGlobalSearchStrategyMUST, after receiving matched IDs fromsearch-service, callproduct-catalog’sGetProductDetailsByIDsandinventory-service’sGetProductPricing(both gRPC) to hydrate the matched IDs into displayableProductrecords, dropping any ID with no detail or pricing counterpart rather than failing the whole request. - FR-06 (Offset/Limit Pagination):
searchProductsMUST acceptoffset/limitparameters, andsearch-service’s aggregation pipeline MUST apply them via$skip/$limitinside the$facetdatabranch. (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-serviceMUST expose a REST suggest endpoint (GET /client/api/v1/product/full-search, served bySuggestProducts) thatui-applicationcalls directly via Dio — independent of the GraphQLsearchProductsquery used for the results grid. Typing MUST NOT triggersearchProducts; 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_demographicsvia a$unwind+$groupaggregation, not bycategory.id. - FR-10 (Keyword Pick Sets Gender Filter): Selecting a demographic-scoped keyword suggestion MUST auto-apply that demographic as a
gendersfilter value on the subsequentsearchProductscall, folded into the samegendersparameter the structured filter sheet uses — no separate field.
Filter schema (independent of the search index)
- FR-11 (Filter Schema Endpoint):
shop-serviceMUST exposeGET /api/v1/filter/schema, sourced from its own admin-curatedcategory_mappingcollection joined againstproduct-catalog’sCategoryQueryService.GetCategoriesByIDs(gRPC) andshop-service’s own category-group image lookup — independent ofsearch-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
searchProductsusing 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-serviceMUST subscribe toproduct-catalog’s product-event Pub/Sub topic (own subscription, distinct from any other consumer of that topic) and, on each event, map the payload’sEventType(product created, basic info/specification updated, cloned, published, archived, or deleted) to an upsert or status change on the correspondingproduct_searchdocument — 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-serviceMUST subscribe toinventory-service’s inventory-search Pub/Sub topic and update the matchingproduct_searchdocument’s coarseinventory.price_min/price_max/total_stock/is_availableblock from the event payload. - FR-16 (Ordered Stock-Status Ingestion):
search-serviceMUST subscribe, with Pub/Sub message ordering enabled and keyed by product ID, toinventory-service’s stock-balance-status-changed topic, and update the matching SKU’sis_in_stock/stock_statusfields insideproduct_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 leaveproduct_searchshowing a shopper stock availability that’s actually wrong, not just stale. - FR-17 (SKU Compliance/Pricing Ingestion, Shared Topic, Status-Filtered):
search-serviceMUST subscribe, via its own independent subscription, to the samesku-compliance-pricing-upsertedPub/Sub topic thatproduct-catalog’s publish-readiness gate already consumes (see ADR-00005) — not a second, duplicate topic — and MUST process only events whosestatusfield is"COMPLETED", discarding the same operation’s earlier"PROCESSING"/"FAILED"events on this topic, to populate per-SKU pricing/attribute rows inproduct_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-servicehas 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
$searchquery MUST include a mandatory tenant-scoping clause in itscompound.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 reachproduct_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 toproduct-catalog’s publish-readiness gate. Three ofsearch-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’ssearchProductsgRPC call norsearch-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.
Related Documents
- BRD-006 — Scalable Search Product
- SR-005 — Mobile App Storefront Configuration System Requirements (FR-14, NFR-05 — search dispatch and one-directional dependency)
- ADR-00005 — Event-Driven Catalog Synchronization, Local Publish-Readiness Gate (the
sku-compliance-pricing-upsertedtopic FR-17 shares a subscription source with) - ADR-00007 — MongoDB Atlas Search for Product Search
- ADR-00017 — Independent Pub/Sub Streams for Catalog-to-Search Synchronization
- Architecture: Scalable Search Product
- Technical Debt — Scalable Search Product Gaps
- search-service
- shop-service