KatInterview

Build a Production RAG Pipeline with Strict Latency Requirements

Machine LearningModel answer
HardModel answerMachine Learningretrieval-augmented-generationsystem-designlatency-optimization

Last updated

Design an end-to-end retrieval-augmented generation architecture for customer support that meets p99 latency targets under 1.5s while handling multi-tenancy and scale.

You're building a retrieval-augmented generation pipeline to power an AI assistant that answers customer support questions. The system must retrieve relevant information from a knowledge base and generate grounded responses while meeting strict performance requirements.

Requirements

Performance targets:

  • p99 latency under 1.5 seconds
  • Support 50 queries per second at peak load
  • Handle 10 million documents across the knowledge base

Functional requirements:

  • Multi-tenant architecture with complete data isolation
  • Document updates must be searchable within 5 minutes
  • Deletions must take effect immediately
  • Responses must include citations to source material
  • System should refuse to answer when confidence is low

What to design

Present a complete architecture covering:

  1. Ingestion pipeline: How documents are processed, chunked, and indexed
  2. Retrieval strategy: Vector search, keyword search, or hybrid; index selection and configuration
  3. Ranking and filtering: How you select the most relevant content
  4. Generation pipeline: LLM integration, prompt construction, and streaming
  5. Caching strategy: What to cache and how to invalidate
  6. Safety mechanisms: Input/output validation and hallucination prevention
  7. Multi-tenancy: How you isolate tenant data and enforce access controls
  8. Failure handling: What happens when retrieval fails, timeouts occur, or cache is stale

Additionally:

  • Capacity planning: Estimate infrastructure costs and sizing for the index, compute, and API calls
  • Evaluation framework: Define metrics and design an experiment to compare retrieval approaches
  • Prioritization: If you had limited time, what would you focus on first and what could you defer?

Provide concrete technology choices, latency budgets per component, and quantitative reasoning where appropriate.

Hints

Hint 1

Break down the 1.5s budget across pipeline stages: guardrails, retrieval, reranking, and generation each need allocated time

Hint 2

Consider both dense embeddings and lexical search - each excels at different query types (paraphrases vs exact product codes)

Hint 3

Multi-tenant isolation requires filtering at the infrastructure level, not just in application logic

Hint 4

Design for failure: what's your fallback when the top retrieved documents have low relevance scores?