KatInterview

Document-Grounded Chat at Scale: Upload, Index, and Serve Sessions

System DesignModel answer
HardModel answerSystem Designragsystem-designasync-ingestion

Last updated

Design a multi-document chat backend where each session accepts up to 200 files, covering async indexing, latency budgets, safe caching, and rate-limit-aware admission control.

You are designing the backend for an enterprise assistant that answers questions over user-supplied files. In a single session a user can upload up to 200 documents (PDF, DOCX, TXT, CSV) totaling hundreds of megabytes, then ask questions across them and continue a multi-turn conversation with streamed answers.

Stated targets:

  • More than 100,000 active sessions.
  • Response time under 3 seconds end to end.
  • Time to first streamed token under 500 ms.
  • Uploaded documents and their vectors expire after 24 hours.

Several facts are not given: page counts, parsing complexity, output length, request arrival rate, and model-provider quotas. Active sessions are not the same as simultaneous generations, and upload, parsing, chunking, embedding, retrieval and generation are separate stages.

Explain how you would interpret, budget and validate these targets, and how you would stop document processing or provider throttling from overwhelming the service.

Part 1 - Upload and asynchronous ingestion. Design the path from upload to a searchable index without buffering or parsing files in the web gateway. Cover status reporting, retries, and what boundary of "indexed" queries can see.

Part 2 - Meeting and measuring query latency. Allocate the critical path across retrieval, context assembly and generation. Describe caching, including when a semantic cache may safely reuse an answer and when it may not.

Part 3 - Scaling under quota pressure. Describe admission control, handling of provider 429 responses, and backpressure between ingestion and interactive queries.

State the clarifying questions you would ask first and the assumptions you adopt.

Hints

Hint 1

Start by pinning down what each target measures: does the 3 s figure include the last generated token, does it apply only after ingestion finishes, and at which percentile? Convert 'active sessions' into an estimate of concurrent requests.

Hint 2

Keep the gateway thin: issue scoped, time-limited direct-to-object-store uploads, then drive idempotent per-document stages through a queue. Give each document a state and give queries an explicit corpus version or a declared partial-readiness rule.

Hint 3

Any cache key must encode who is asking and what they are allowed to see: tenant, user, session corpus version, conversation context, prompt and model version. Reserve provider capacity for interactive traffic and give ingestion a separate, lower-priority budget.