ADR-00007 — MongoDB Atlas Search for Product Search
- Status: Approved / Implemented
- Date: 2026-09-27
- Authors: Engineering Team
Context
search-service maintains a denormalized product_search MongoDB collection, kept in sync via Pub/Sub events from product-catalog and inventory-service (see search-service). Once that collection exists, a shopper’s keyword search still needs to be scored and ranked — an exact find() filter can’t rank “classic dress” above “dress classic,” can’t tolerate a typo, and can’t score a title match higher than a description match. A full-text search capability was needed on top of product_search, and the choice was between adding that capability to the database the data already lives in, or standing up a separate search engine and keeping it synchronized with product_search.
Decision Drivers (FRs & NFRs)
See SR-006 for the full detail.
- FR-02/FR-03 (Full-Text Ranking & Typo Tolerance): Search must score and rank matches on
title/tags/category.name/description, with fuzzy matching for typo tolerance — a plain equality/regex filter cannot do this. - NFR-01 (Index-Backed Query): Matching must run against an index, not a collection scan, so latency doesn’t grow with catalog size.
- NFR-03 (Bounded Catalog-to-Search Freshness): A product/price/stock change must become searchable within a bounded delay, without a separate synchronization pipeline beyond the event-driven sync
search-servicealready performs intoproduct_search. - Cost and operational footprint — this is a multi-tenant platform where every additional stateful component (a second data store, a second cluster to provision, monitor, and scale) is infrastructure cost multiplied across every tenant, not a one-time cost.
Options Evaluated
Option 1 — MongoDB Atlas Search, indexed directly on product_search (CHOSEN)
search-service defines an Atlas Search index (product_search_index) directly on its own product_search collection, and queries it via a $search aggregation stage with a compound operator (mandatory tenant/status filter, conditional category/gender/variant/price/discount must clauses, and fuzzy-boosted text should clauses on title/tags/category.name/description) — see search-service’s product_search_crud_rep.go.
- Pros:
- Storage and infrastructure cost. Atlas Search runs as a search index colocated with the existing Atlas cluster — there is no second cluster, no second class of infrastructure to provision, size, and pay for independently of the primary data store. A standalone search engine is an entirely separate stateful service with its own storage footprint, its own scaling/sizing decisions, and its own operational cost — multiplied across a multi-tenant platform where that cost scales with every tenant’s catalog, not just once.
- Data synchronization stays simple. Because the index sits directly on
product_search, Atlas Search keeps itself current with that collection automatically —search-servicenever has to run or operate a second sync pipeline (a connector, a change-stream forwarder, a batch ETL job) to push data from MongoDB into an external engine’s own storage.search-servicealready does one synchronization job (Pub/Sub events →product_search, see search-service); Atlas Search adds zero additional synchronization surface on top of that. - Full-text capability without giving up either property. Atlas Search is itself built on Apache Lucene under the hood, so it provides the same class of ranked, fuzzy, multi-field full-text query capability a standalone Lucene-based search engine would — without the cost and sync trade-offs of running that engine as a separate service.
- Cons & Accepted Trade-offs:
- Atlas Search index configuration and query authoring (the
compound/should/fuzzyshape) is specific to MongoDB Atlas — this is not a portable Lucene query DSL the team could lift directly into a different document store later. - Relevance-tuning tools (custom scoring functions, some ranking/aggregation features standalone engines expose more directly) are less extensive than a dedicated search engine’s own ecosystem — acceptable today because current requirements (FR-02/FR-03) are met, revisit only if a genuine relevance gap surfaces.
- Pagination is offset-based (
$skip/$limitinside a$facet), which has its own deep-page scaling limit — tracked separately in Technical-Debt-00006, not a consequence of choosing Atlas Search itself.
- Atlas Search index configuration and query authoring (the
Option 2 — Standalone search engine (e.g. Elasticsearch/OpenSearch), synchronized from MongoDB
- Pros:
- A larger, more mature relevance-tuning and query-DSL ecosystem, purpose-built for search as its only job.
- Portable across document stores — not tied to one database vendor’s search feature.
- Cons (Why Rejected):
- Doubles the storage/infrastructure footprint. The product data already lives in
product_search; a standalone engine means storing a second, separately-indexed copy of that same data in its own cluster — a real, ongoing storage and infrastructure cost with no data-model benefit search-service doesn’t already get from Atlas Search. - Introduces a synchronization pipeline that doesn’t otherwise need to exist. Keeping an external engine’s index current with
product_searchrequires a connector, a change-stream forwarder, or a batch job — a second synchronization concern layered on top of the Pub/Sub-driven syncsearch-servicealready runs, purely to keep two copies of the same data agreeing with each other. - No current requirement (SR-006’s FR-02/FR-03) needs a capability Atlas Search can’t provide — the added cost and sync complexity would buy relevance-tooling headroom the product doesn’t need yet.
- Doubles the storage/infrastructure footprint. The product data already lives in
Final Decision
Option 1 is selected. MongoDB Atlas Search — indexed directly on the product_search collection search-service already maintains — meets every current full-text search requirement (ranking, fuzzy matching, multi-field scoring) via its Lucene-based query engine, while avoiding both the storage/infrastructure cost and the data-synchronization overhead of operating a second, standalone search cluster. Revisit this decision only if a genuine relevance or scale limitation surfaces that Atlas Search’s own feature set cannot address — not preemptively.