Discovery Platform Low-Level Design
This document is the implementation companion to Discovery platform architecture. Compass owns policy and request construction. TypeSense executes primary retrieval and ranking.Runtime Contract
Discovery Product Document
Index one canonical product family, not one document per SKU/size variant.Query Understanding
Pipeline
Intent signals
Ambiguous queries may retain multiple candidates. Log confidence and evidence in the Compass explain record.
Numeric extraction
Use typed parser rules, not text search, for explicit values.
Only high-confidence explicit values become hard filters. Ambiguous values, such as
light sunscreen, become controlled ranking preferences or later hybrid-search signals.
Query-plan type
spf above 50 sunscreen for oily skin under 700, Compass creates:
TypeSense Request Compilation and Ranking
Compass loads the ranking profile and matching active rules, then compiles TypeSense parameters. TypeSense performs the actual relevance score, filtering, grouping, sorting, curation, and pagination.Ranking precedence
Eligibility and Final Validation
Push broad filters into TypeSense, then revalidate in Compass.Core Surface Designs
The following sections are the implementation contracts for the four core discovery surfaces. They use one canonical product collection and one shared eligibility/ranking policy; they do not create separate product indexes per page type.Search
Search API contract
Search execution sequence
search_id identifies the exact returned list. The explain record stores the raw query, normalized query, QueryPlan, TypeSense request, active rule/profile/configuration versions, candidate exclusions, result positions, fallback step, provider, and latency.
Search profiles
Profiles are stored in Compass and compiled to TypeSense request parameters. They are not code branches.Filters, sorting, grouping, and pagination
Compass always adds mandatory filters, then adds explicit user filters and high-confidence extracted filters.displayVariants provides the price/variant shown on the card. Pagination always occurs after TypeSense grouping. A filter or sort change resets to page one server-side.
Sort semantics:
Search fallback ladder
Fallback is explicit and measured. It is not a hidden retry loop.fallback.step; PostHog records it. TypeSense nohits_queries tracks raw engine no-hit demand, which is distinct from a fallback-rescued user result.
Search failure behavior
Search measurement
Required PostHog properties forsearch_executed include search_id, raw/normalized query under access policy, intent, extracted entities/filters, profile/version, configuration version, provider, results and positions, result count, fallback, latency, platform, and surface.
Track zero result, fallback rescue, reformulation, search-to-PDP, search-to-cart, search-to-order, latency, rule exposure, and index freshness. Compare these against Netcore during migration.
Autosuggest
Design principle
Autosuggest is a grouped router, not a smaller flat search-results page. TypeSense identifies matching candidates and maintains native popular-query data. Compass determines group, destination, privacy/safety, curation, and final suggestion quality.Collections
Use one main product collection and small entity collections. Do not create a separate product collection for every suggestion type.analytics_popular_queries_v1 is a normal TypeSense destination collection populated by its popular_queries native analytics rule. It is the popular-query source; no separate leaderboard service is required.
Suggest API contract
150-250ms, cancels an older request when a newer prefix exists, and does not call suggest for a stale input value. Compass uses a stricter latency budget than full search.
Suggest execution sequence
Acne UV product family must outrank a broad Acne concern. A popular query never bypasses safety or quality gates.
Suggest response contract
Popular query quality gate
Before a TypeSense popular query is displayed, Compass checks:- It is not a prescription, medical, sensitive, abusive, or blocked phrase.
- It has an acceptable recent successful-result rate and availability profile.
- It is not a near duplicate of an existing entity/product suggestion.
- It is not expired/blocked by a merchandising or compliance rule.
- It has enough recent traffic according to the configured threshold.
Empty-prefix suggestions
For an empty prefix, do not run normal entity multi-search. Return, in policy order:Suggest analytics
The client sends visible suggestion impressions only after the dropdown is visible. Suggestion clicks includesuggestion_id, group/type, rank, source, prefix, destination, session, and resulting search/page context. suggestion_shown and suggestion_clicked go to PostHog; native TypeSense analytics continues to aggregate actual search submissions rather than every keystroke.
Browse and PLP
Page definition
Browse pages are query templates overdiscovery_products_v1, not separate product indices.
Browse request flow
Filter configuration
filter_by expressions from clients. Empty-filter states return clear removal/relaxation choices; they never silently change user filters.
Browse merchandising and content
Page-level rules use the same control plane as search:- Pins/hides compile to TypeSense overrides or request-time controls.
- Simple boosts/buries compile to profile/evaluation parameters.
- Content slots are resolved by Tetris/CMS after product retrieval.
- Card badges derive from controlled product flags and Compass rules; badge priority/max count is configuration.
Browse SEO and events
Stable page IDs and canonical URLs are independent of display names. Renames preserve redirects. Filtered URLs receive explicitindex/noindex policy.
PostHog plp_viewed records page ID/type, products/positions, profile/config version, active filters, sort, and content-slot IDs. Client events record visible cards, filter/sort changes, content interactions, and PDP clicks.
Recommendations
Design boundary
Recommendations use a pipeline, not generic “similar products” search. TypeSense can retrieve attribute-compatible candidates, but Compass applies the strategy, routine logic, safety, exclusions, overrides, fallback, and measurement.Widget request contract
Strategy configuration
TypeSense recommendation retrieval
For attribute-based similarity, Compass builds a constrained TypeSense query from the anchor product:best_used_with, the query must prefer a complementary routine step and exclude duplicate actives. For similar, it can retain the same product type/concern. The strategy decides this; a generic vector-nearest-neighbor query is insufficient.
Routine and safety policy
Compass stores controlled relationship tables:- Anchor product itself.
- Rx products from all promotional widgets.
- Out-of-stock or unlistable products.
- Forbidden category/widget combinations.
- Same routine step where complementarity is required.
- Duplicate active ingredients where redundancy is forbidden.
- Known ingredient conflicts and declared safety cautions.
Recommendation merchandising, fallback, and events
Merchandisers can pin, hide, cap, floor, or fully replace a widget with a curated list through the same Compass rule model. Widget rules are scoped by widget type, surface, anchor product/family/category, and schedule.End-to-End Use Cases
Exact product
Brand
Category, ingredient, concern
Hinglish
Typo and structured search
Autosuggest
Browse/PLP
Semantic/hybrid search
Redirect, medical, and fallback
Recommendations
Merchandising Compilation
Compass PostgreSQL is the rule source of truth. TypeSense is an execution target.typesense_rule_sync records TypeSense resource type/ID, source rule version, pending|synced|failed status, time, and error. Disabling a rule immediately removes it from Compass active configuration and queues TypeSense deletion.
For a pin:
Event Contract and Routing
Portable event envelope:
Compass returns an opaque signed
discovery_context_token per result. Clients pass it unchanged to clicks and add-to-cart; Vector/Medusa validates it and persists primary discovery attribution on the cart line. The order event uses that persisted line attribution.