KatInterview

Building a Filterable Catalog Search with Live Facet Counts

System DesignModel answer
MediumModel answerSystem Designsearchinverted-indexfaceting

Last updated

Design a billion-item catalog search service with relevance ranking, filters, accurate facet counts, stable pagination, and second-level freshness for fast-changing price and stock data.

Problem

You are designing the search backend for a very large online marketplace. Shoppers type free-text queries such as "wireless noise cancelling headphones" and then refine the results with facets: brand, category tree, price range and minimum customer rating. Besides the ranked list of products, each response must include facet counts showing how many matching products fall into each bucket.

Requirements

Functional

  • Relevance-ranked text search across titles, descriptions and keywords.
  • Filtering by category, brand, rating and price range, with facet aggregations returned alongside the hits.
  • Stable pagination: no item duplicated or skipped across page boundaries while the user browses.
  • Price changes and out-of-stock events must show up in results within a few seconds.

Non-functional

  • 1 billion active products.
  • 50,000 queries per second at peak.
  • p99 latency below 150 ms, including facet computation.
  • 99.99% availability on the read path.
  • 5,000 catalog attribute updates per second, plus up to 50,000 price/stock updates per second.

What to cover

  1. Overall architecture and API: endpoints, request parameters (query, filters, facets, cursor) and response shape.
  2. Index layout and storage: inverted index for text, columnar per-document values for filtering and counting, and the sharding approach (document-based vs. term-based).
  3. The life of a query: coordinator, leaf shards, posting-list intersection, scoring, facet counting and scatter-gather merging.
  4. Keeping volatile fields fresh: compare naive re-indexing with hybrid designs such as in-memory side stores, delta segments or two-phase hydration.
  5. Pagination: offset-based vs. keyset/cursor-based paging at this scale, and the trade-offs.

Use back-of-the-envelope numbers to justify your choices.

Hints

Hint 1

Separate the data by rate of change: titles and attributes change slowly and can go through immutable index segments, while price and stock change constantly and should not force a document rewrite.

Hint 2

Partition documents (not terms) across shards so each shard can match, score and count facets on its own; then think about what the coordinator must merge, and which facet dimensions can be merged exactly versus only approximately.

Hint 3

For pagination, ask what happens to deep offsets in a scatter-gather system (each shard must return offset+limit items) and what a cursor needs to encode (a consistent view plus the last sort key with a unique tiebreaker).