MediumExperience level: 3-5 years · 8-15 years1 min read

How would you design a search system (e.g. product or document search)?

Reviewed by Gurusankar M.

Asked inAmazonGoogleMicrosoft
#search#inverted index#elasticsearch#indexing#ranking
Report issue

Short Answer

Build an inverted index (term → list of documents) so queries are fast lookups, not full scans. Ingest documents through an analysis pipeline (tokenize, lowercase, stem), index them (Elasticsearch/OpenSearch), keep the index eventually consistent with the source via events, and rank results (TF-IDF/BM25 + business signals). Add pagination, filters, and typo tolerance.

On this page

Concept Made Simple

Coffee Chat Question

“How would you design a search system (e.g. product or document search)?”

Remember It Faster

Mind Map Answer

Inverted index
term → documents (fast lookup)
Analysis
tokenize, lowercase, stem
Sync
index from source via events (eventual)
Rank
BM25/TF-IDF + business signals

Think Beyond the Expected

What If?

Why use Elasticsearch instead of SQL LIKE '%term%' for search?

LIKE '%term%' can't use an index (non-SARGable) → full table scan, no relevance ranking, no stemming/typo tolerance. An inverted index looks up matching docs in near-constant time and ranks them by relevance (BM25), with analyzers for stemming/synonyms — purpose-built for search where a relational LIKE collapses at scale.

Real World

Product/document search runs on Elasticsearch/OpenSearch fed asynchronously from the primary DB (CDC/events); the index is eventually consistent, and ranking blends text relevance with business signals (popularity, recency).

Interviewer's Expectation

Keywords they're listening for:

  • inverted index
  • analysis pipeline
  • async indexing / eventual consistency
  • relevance ranking (BM25)
  • why not SQL LIKE

Common Mistakes

  • SQL LIKE '%...%' for real search (full scans)
  • Synchronous indexing on the write path
  • Ignoring relevance ranking

Best Practices

  • Use an inverted index (Elasticsearch/OpenSearch)
  • Index asynchronously from the source of truth
  • Blend text relevance with business signals

Follow-up Questions

  1. How do you keep the search index in sync with the DB?
  2. How does relevance ranking (TF-IDF/BM25) work?
  3. How do you add typo tolerance / autocomplete?

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: Databases (System Design)
Interview question: "How would you design a search system (e.g. product or document search)?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.
Open inChatGPTGeminiClaude

Was this answer helpful?

Affiliate links

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.