ADR-00016 — Query-Time Computation vs. a Dedicated Recommendation Engine for Storefront Merchandising Sections

By Engineering Team•September 29, 2026•5 min read
  • Status: Approved / Implemented
  • Date: 2026-09-29
  • Authors: Engineering Team

Context

BRD-008 requires six product-discovery sections (New Arrivals, Top Products, Most Popular, Just For You, Category Groups, Flash Sales) to each show shoppers a relevant, currently accurate set of products. This ADR documents why every one of these sections is powered by direct queries — a MongoDB aggregation against product-catalog, a SQL query against inventory-service’s PostgreSQL store, joined by shop-service at request time — rather than a dedicated recommendation or ranking engine computing these sections ahead of time.

This decision was made alongside a specific, deliberate scoping choice: three of the six sections (Top Products, Most Popular, Just For You) run on interim ranking logic today because no shopper-behavior signal (views, clicks, purchases) exists anywhere in this platform yet. A genuine recommendation engine — for “Just For You” specifically, and potentially “Most Popular” — is treated as future work gated on that signal existing, not as an alternative rejected on its own technical merits. See Technical Debt — Storefront Merchandising Section Accuracy Gaps for the per-section detail behind that gap.


Decision Drivers

See SR-008 for the full requirement list.

  • No behavioral signal exists yet to feed a recommendation engine (SR-008 NFR-02). Views, clicks, and purchases are not captured anywhere today — a recommendation engine built now would have nothing real to learn from.
  • Real-time price/availability reflection (SR-008 NFR-04, BRD-008 BR-07). A shopper must never see a stale price or an unavailable product in a discovery section.
  • Ship the capability now, without new infrastructure. ADR-00008 already established product-catalog (MongoDB) and inventory-service (PostgreSQL) as each service’s data store; both already support the query shapes these sections need without a new system being introduced.
  • Flash Sales is a genuinely time-boxed, discount-driven section (SR-008 FR-06), where the ranking criterion (savings amount) is already a real, well-defined signal sitting directly in inventory-service’s existing pricing data — not a case needing a learned model at all.

Options Evaluated

Option 1 — Query-time computation, joined in shop-service (CHOSEN)

Each section is computed by a direct MongoDB aggregation (product-catalog) and, where pricing or discount ranking is involved, a direct SQL query (inventory-service), joined by mongo_product_id in shop-service at request time.

  • Pros:
    • Requires no new infrastructure — both underlying data stores and their query capabilities already exist for other purposes (ADR-00008).
    • Every section reflects inventory-service’s current SKU/pricing state at the moment of the request — there is no separate cache or precomputed snapshot that can drift from what’s actually purchasable, satisfying BR-07.
    • Flash Sales’ ranking criterion (savings amount) is a real, already-correct signal computed directly in SQL — this section needed no proxy or heuristic at all, unlike the other three.
    • Lets the platform ship all six sections now, rather than blocking section delivery on building a recommendation engine that — with no behavioral data to train on — would not yet be meaningfully more accurate than a well-chosen interim heuristic.
  • Cons & Accepted Trade-offs:
    • Three sections (Top Products, Most Popular, Just For You) run on interim proxies — recency and demographic/tag matching — rather than a true popularity or personalization signal, because no behavioral data exists to do better. This is accepted as a documented, tracked starting point (see Technical Debt — Storefront Merchandising Section Accuracy Gaps), not a permanent design choice.
    • A product id present on only one side of a cross-service join (MongoDB detail or Postgres pricing) is silently dropped from its section rather than surfaced — an accepted interim behavior, also tracked as technical debt.

Option 2 — Build a dedicated recommendation/ranking engine now

Stand up a dedicated service (or third-party integration) that computes ranked product lists for these sections, ahead of shipping the section capability.

  • Cons (Why Rejected):
    • There is no shopper-behavior data anywhere in this platform to train or drive such an engine — building one now would mean building a recommendation system with nothing real to recommend from, likely falling back to the same recency/tag heuristics Option 1 already uses directly, but behind a materially larger new system.
    • Introduces a new infrastructure and operational surface (a ranking/ML service, its own data pipeline, its own deployment) disproportionate to the validated need today — no NFR in SR-008 currently requires learned ranking; three of the six sections don’t need one at all (New Arrivals, Category Groups, Flash Sales are each already served correctly by a direct, well-defined query).
    • Blocks shipping the section capability shoppers need today on a much larger, separately-scoped project whose real prerequisite (a behavioral-event pipeline) doesn’t exist yet.

Option 3 — Precomputed/materialized sections via a scheduled batch job

Compute each section’s product list on a schedule (e.g. hourly) and serve a cached snapshot, rather than querying live on every request.

  • Cons (Why Rejected):
    • Directly conflicts with BR-07/NFR-04’s real-time price/availability requirement — a batch-computed Flash Sale list in particular would risk showing a discount that has since ended or a product that’s gone out of stock between batch runs, which is a materially worse outcome for a time-sensitive section than the small per-request query cost Option 1 accepts.
    • Adds a new scheduled-job and cache-invalidation surface (staleness windows, invalidation-on-price-change, job-failure handling) to solve a problem the direct per-request queries already handle at acceptable latency — the request-time fan-out these sections need is a handful of indexed queries, not a full catalog scan.

Final Decision

Option 1 (query-time computation, joined in shop-service) is selected. It satisfies BRD-008’s real-time accuracy requirement without new infrastructure, and lets three of the six sections (New Arrivals, Category Groups, Flash Sales) already be fully correct against a real, well-defined criterion. The remaining three sections’ reliance on interim proxies is not a shortcoming of this architectural choice — it is a direct consequence of no shopper-behavior signal existing yet anywhere in the platform, which is equally true under Option 2. A genuine recommendation engine for “Just For You,” and potentially “Most Popular,” remains this platform’s intended long-term direction for those two sections — it is deferred pending a dedicated event-tracking pipeline (a separate, future project), not rejected on technical merit. See Technical Debt — Storefront Merchandising Section Accuracy Gaps for the specific, tracked gap behind each interim section.