← Lessons

quiz vs the machine

Gold1430

System Design

Search and Filtering for Products

Powering keyword search and faceted filters with an inverted index.

5 min read · core · beat Gold to climb

Beyond the database

Product search needs free text matching, relevance ranking, typo tolerance, and faceted filters like brand, price, and size. A relational database with LIKE queries cannot do this at scale, so stores use a dedicated search engine built on an inverted index.

The inverted index

An inverted index maps each term to the list of products that contain it. A query intersects these lists, which is far faster than scanning every row. The engine also computes a relevance score so the best matches rank first.

Faceted filtering

Facets are aggregations: for the current query, how many products fall in each brand or price band. Shoppers narrow results by clicking facets, and the engine recomputes the matching set and counts.

Keeping it fresh

The search index is derived data. Catalog changes flow in through an indexing pipeline, so the index is eventually consistent with the source of truth.

Key idea

Serve product search from an inverted index with relevance ranking and facets, kept fresh by an indexing pipeline.

Check yourself

Answer to earn rating on the learn ladder.

1. Why use a search engine instead of database LIKE queries?

2. What are facets in product search?

3. What keeps the search index up to date?