Back to System Design

SYSTEM DESIGN · QUESTION 116

How would you design a document search service?

On this page
Advanced 4 min read
Interview-ready answerThe concise version to remember

I would clarify corpus size, update frequency, ranking, access control, and query latency. An ingestion pipeline extracts and normalizes documents, builds an inverted index with metadata, and publishes index versions. Query services retrieve candidates, apply permission filters and ranking, then return snippets and source links. Support incremental updates, deletion propagation, index rebuilds, and observability for relevance as well as availability.

LET'S MAKE IT SIMPLE

First, the idea in plain English

Searching every document for every query is expensive. A search index organizes terms and document metadata ahead of time so the service can quickly find likely matches. The index must stay synchronized with source documents, and results must respect who is allowed to see them.

A USEFUL COMPARISON

Picture it this way

A book index lists topics and the pages where they appear. Updating the book requires updating the index too. A search service creates a much larger, frequently updated index and checks permissions before returning results.

FOLLOW THE JOURNEY

Build a searchable index and apply access-aware ranking at query time

Show document ingestion, indexing, retrieval, permission filtering, and result ranking.

Build a searchable index and apply access-aware ranking at query timeShow document ingestion, indexing, retrieval, permission filtering, and result ranking.Search architecture
01Ingest documentsExtract text, normalize fields, and record source identity and permissions.
02Build indexCreate term postings and searchable metadata.
03Retrieve candidatesParse query and find matching documents.
04Filter and rankEnforce access, score relevance, and return useful snippets.

This simplified visual highlights the main relationships. In practice, the exact design depends on the requirements; Fast matches are not useful if irrelevant or unauthorized.

Documents are extracted and indexed with metadata; queries retrieve candidates, apply access-control filters and ranking, and return snippets with source links.

How to read this visual
This simplified visual highlights the main relationships. In practice, the exact design depends on the requirements; Fast matches are not useful if irrelevant or unauthorized.

UNDER THE HOOD

How it works, step by step

01

Ingest documents

Extract text, normalize fields, and record source identity and permissions.

Why it matters: Search quality depends on usable, authorized content.

02

Build index

Create term postings and searchable metadata.

Why it matters: Precomputation reduces query-time work.

03

Retrieve candidates

Parse query and find matching documents.

Why it matters: Candidate retrieval narrows the ranking problem.

04

Filter and rank

Enforce access, score relevance, and return useful snippets.

Why it matters: Fast matches are not useful if irrelevant or unauthorized.

OUTSIDE THE TEXTBOOK

A practical example

An enterprise search service indexes approved policy documents. When an employee searches, it retrieves candidate passages, filters them using the employee’s current access rights, ranks by text relevance and freshness, and links to the source. Deletion or permission changes trigger index updates and cache invalidation.

GO A LITTLE DEEPER

Technical details that matter

  • Inverted indexes map terms to documents and support efficient lexical retrieval.
  • Ranking may combine term relevance, freshness, and quality signals; validate with judged query sets.
  • Permission filtering before or during retrieval must prevent unauthorized snippets from leaking.

MAKE A GOOD CHOICE

When is this useful?

  • Enterprise documentation and knowledge portals.
  • Product catalogs and internal developer search.
  • Retrieval systems that supply candidate passages to other applications.
Consider the alternative

For a small corpus, database full-text search may be sufficient; vector retrieval can complement lexical search for semantic queries.

WATCH OUT FOR

Common misunderstandings

  • Returning snippets before checking document permissions.
  • Treating index availability as evidence of search relevance.
  • Ignoring deletion and permission changes in cached results.

REAL-WORLD TRADE-OFFS

Limitations and failure cases

  • Index freshness can lag source changes.
  • Relevance requires evaluation and ongoing tuning.
  • Access-control integrations and indexing can be complex.

WHAT TO REMEMBER

Key takeaways

  1. 1Index ahead of query time for fast retrieval.
  2. 2Enforce permissions before returning documents or snippets.
  3. 3Measure relevance, freshness, and service health separately.

PRACTICE THE FOLLOW-UP

What might an interviewer ask next?

How would you update an index without downtime?

Build a new version alongside the current one, validate it, then switch a version pointer or route traffic gradually.

How do you measure search quality?

Use judged queries and ranking metrics such as precision at k or NDCG, then review failures and user behavior with privacy safeguards.

SAY IT OUT LOUD

How to explain this in an interview

“I would clarify corpus, update frequency, permissions, and ranking needs. An ingestion pipeline normalizes documents and builds a versioned inverted index. At query time the service retrieves candidates, enforces access control, ranks them, and returns source-linked snippets. I would support incremental updates and measure relevance and freshness separately from uptime.”

Continue your learning path

Connect this question to the roadmap topic it supports.

Open roadmap topic