KatInterview

Design a Versioned Document Storage and Search Service

System DesignModel answer
MediumModel answerSystem Designsystem designstorageindexing

Last updated

Design a system that stores versioned text documents and supports full-text search across any historical version at scale.

Design a Versioned Document Storage and Search Service

Background

Your company builds a collaborative writing tool used by teams to draft, edit, and review long-form documents (think wikis, runbooks, and technical specs). Each document can be edited many times a day. Users need to:

  1. Read any past version of a document.
  2. Search for a keyword or phrase and see matching results — with the option to search only the latest version or any version of every document.

Functional Requirements

  • Create, update, and delete documents.
  • Retrieve document content at a specific version number.
  • Full-text search across current versions (required), and optionally across all historical versions (stretch goal).
  • Search results should include document ID, version number, a short snippet, and a relevance score.

Non-Functional Requirements

  • Scale: 5 million documents, average 50 versions each, average document size 10 KB.
  • Write throughput: ~2,000 document saves per second at peak.
  • Search latency: p99 < 500 ms for current-version search.
  • Read latency for content: p99 < 100 ms.
  • Durability: no data loss on a single node failure.

What is expected

Design the end-to-end system. Cover:

  • API design (key endpoints)
  • Data model (how you store versions efficiently)
  • Architecture (components and data flow)
  • Indexing strategy for full-text search
  • Deep dives on at least two areas of your choice (e.g., storage efficiency, index fan-out, consistency)
  • Trade-offs you made and why

Hints

Hint 1

Think about whether you store each version as a full snapshot or as a diff/delta — what does each choice cost you at read time vs. storage?

Hint 2

A search index over all 250 million versions would be enormous; consider what subset you actually need to index and how you'd handle the stretch goal incrementally.

Hint 3

Consider how writes flow: the save path and the index update path can be decoupled with a queue to protect search availability from write spikes.