KatInterview

Enterprise Document Q&A with Retrieval and Generation at Scale

System DesignModel answer
HardModel answerSystem Designragvector-searchml-system-design

Last updated

Design an end-to-end, multi-tenant retrieval-augmented question-answering platform over large, mixed-format document collections, with strict isolation, freshness, latency and cost targets.

Problem

A company wants to offer a question-answering product over its customers' private document collections. Users ask natural-language questions and receive grounded answers that cite the documents they came from. Design the full production system and justify your main choices.

Requirements

  • Tenancy and security: many customers share the platform. No tenant may ever see another tenant's data, and per-user document permissions must be respected. Data must be encrypted in transit and at rest, and personal data must be handled according to tenant policy.
  • Content: PDFs, web pages, emails, spreadsheets and source code, arriving at up to 10 million documents per day.
  • Freshness: a new or changed document should be searchable in under 5 minutes.
  • Latency: P50 ≤ 800 ms and P95 ≤ 2 s per query.
  • Cost: a defined budget per 1,000 queries.

What to cover

  1. Ingestion: connectors, change capture, parsing of each format, chunking (size, overlap, metadata, tables, code), duplicate detection, and PII redaction.
  2. Embeddings: model choice and dimensionality, multilingual vs. code-specific models, multi-vector chunks, similarity and normalization, and how to migrate between embedding versions.
  3. Indexing: vector index type and parameters (e.g. graph-based vs. quantized inverted-file), a keyword index, sharding, replication, storage tiers, zero-downtime reindexing, and memory/capacity arithmetic.
  4. Retrieval: query understanding, hybrid sparse and dense candidate generation with permission filters and recency weighting, score fusion, deduplication, cross-encoder re-ranking, and a threshold for "can this be answered?"
  5. Prompt construction: context budget, packing, citations, tool use, and routing between models of different cost and quality.
  6. Trustworthiness: attribution checks, abstention, guardrails, prompt injection through retrieved text, and runtime PII enforcement.
  7. Caching and freshness: which caches exist, key design, invalidation on document change, and online index swaps.
  8. Multilingual support.
  9. Scaling, per-stage latency budgets, autoscaling, and disaster recovery (replication, snapshots, RTO/RPO).
  10. Observability and evaluation: retrieval and answer metrics, drift, tracing, offline gold sets, online experiments, and feedback loops.
  11. Cost model and levers, plus the accuracy / latency / cost trade-offs.
  12. Behavior when retrieval is weak.
  13. An API and a data schema for documents and embeddings.
  14. Cloud vs. on-prem, and a phased rollout with experiments and rollback.

State your assumptions and numbers explicitly. Because the scope is wide, show how you prioritize.

Hints

Hint 1

Spend the first few minutes on scale math: convert 10M docs/day into docs/s and chunks/s (including peak), estimate the live corpus, and decide how much of it must be in fast memory.

Hint 2

Treat tenant and permission isolation as a data-plane invariant: inject tenant and ACL filters server-side in every index query, never rely on the prompt, and plan a fallback for filters so selective that approximate search loses recall.

Hint 3

Split the latency budget by stage (query understanding, parallel sparse and dense retrieval, fusion, reranking, generation) and use tiering, quantization and model routing to hit both the latency and cost targets.

Hint 4

Close the loop with evaluation: a gold set for retrieval recall and answer groundedness, calibrated abstention thresholds, and shadow-index plus per-tenant alias flips for safe embedding migrations.