Asked at
URL Shortener (TinyURL)
Asked from Junior level upFoundations & Storage
Distributed Rate Limiter
Asked from Mid level upAPI Gateway & Security
Distributed Key-Value Store
Asked from Senior level upFoundations & Storage
Distributed Notification Service
Asked from Mid level upMessaging & Queues
Distributed Web Crawler
Asked from Mid level upDistributed Systems
Metrics & Monitoring Platform
Asked from Senior level upObservability & Time-Series
Real-Time Chat App (like WhatsApp or Slack)
Asked from Mid level upReal-Time & WebSockets
Social News Feed (like X/Twitter)
Asked from Mid level upSocial & Feed Systems
Ride-Hailing App (like Uber)
Asked from Senior level upGeospatial & Real-Time
Low-Latency Stock Exchange Matching Engine
Asked from Staff level upFintech & Low Latency
Global Video Streaming Platform (like YouTube or Netflix)
Asked from Senior level upMedia & Streaming
Distributed Hotel & Ticket Reservation System
Asked from Mid level upE-Commerce & Transactions
Shared Document Editor (like Google Docs)
Asked from Staff level upReal-Time & Distributed State
Game Leaderboard
Asked from Junior level upCaching & Data Structures
File Sync Service (Dropbox / Google Drive)
Asked from Mid level upStorage
Payment System
Asked from Senior level upPayments & Transactions
Ad Click Aggregation
Asked from Senior level upStream Processing
AI Support Assistant (RAG)
Asked from Senior level upAI Systems
LLM Inference Platform
Asked from Senior level upAI Systems
Enterprise Semantic Search
Asked from Mid level upAI Systems
AI Code Completion
Asked from Senior level upAI Systems
LLM Gateway
Asked from Senior level upAI Systems
AI Agent That Takes Actions
Asked from Senior level upAI Systems
LLM Evaluation Platform
Asked from Senior level upAI Systems
AI Document Processing Pipeline
Asked from Mid level upAI Systems

Design an AI Support Assistant (RAG)

Asked from Senior level upEmerging topicPart of the AI track: start with AI basicsDomain: AI Systems
Concepts to know first:

Answer customers' questions from the company's own help articles and past tickets. Each answer names its sources and stays within a time and cost budget.

An analogy

Like a new support agent with an excellent librarian. Before answering, the librarian fetches the few most relevant pages. The agent then answers only from them, and says where the answer came from.

Where this analogy stops working: A person notices when a page is out of date or does not answer the question. The model may not, so the system needs citations, checks and a hand-off to a person.

Where this design ends up. This is version 3 of 3. Part 5 builds it up from version 1 and says why each part was added.
  1. Clients
    • Chat widget
    • Help documents
  2. Entry
    • Gateway
  3. Services
    • Assistant service
    • Indexer
    • Retriever
    • Reranker
    • Guardrails
  4. Data, outside
    • Vector index
    • Language model
    • Logs and evaluation

1. Requirements and scope

Functional Requirements
  • Answer questions in a chat widget using help articles, product docs and resolved tickets.
  • Cite the sources of each answer. When unsure, say so and hand the chat to a person.
  • Keep each business customer to its own documents, so no customer sees another's files.
  • Stream each answer as it is written, a few words at a time.
Non-Functional Requirements & SLAs
  • First words within about 2 s, and the full answer within about 10 s.
  • A cost per answer within budget. Model tokens are the main cost.
  • Quality measured all the time: is each answer backed by its sources, and was the question resolved?
  • New or changed articles searchable within minutes.
Key Traffic Assumptions: 200,000 questions a day, peaks of about 20 per second. • 500,000 documents split into about 5 million chunks.

2. Back-of-the-envelope numbers

Write Throughput
Indexing: a few thousand document changes a day, embedded in batches
Read Throughput
200,000 ÷ 86,400 ≈ 2.3 questions a second on average, about 20 at peak. Each question needs one embedding, one search, one rerank and one model call
Storage Growth
Index: 5M chunks, each a vector of 1,536 numbers at 4 bytes (about 6 KB) plus its text, ≈ 40 GB. Conversation logs: 200,000 a day × 5 KB ≈ 365 GB a year
RAM Cache Footprint
An answer cache for frequent identical questions and an embedding cache for repeated queries

3. API

POST/v1/chat/sessionsStart a conversation
POST/v1/chat/sessions/{id}/messagesAsk a question; the answer streams back (server-sent events)
POST/v1/feedback{ messageId, helpful }

4. Data model and storage

Storage Strategy: Documents are kept in object storage. A relational database holds their details and who may read them. Search uses a vector index, such as pgvector, OpenSearch or a vector database, beside a keyword index. Conversation logs go to a data warehouse, where answers are evaluated.
CHUNK(id, doc_id, text, embedding, tenant_id, updated_at) · CONVERSATION(id, user_id, started_at) · MESSAGE(id, conversation_id, role, text, sources[], feedback)

5. The design, in three versions

Version 1: Ask the model directly

Send the customer's question straight to a language model.

AI Support Assistant (RAG): Version 1: Ask the model directly Version 1 of 3

The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.

One request, step by step

Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.

Chat widgetAssistant serviceLanguage model123
  • The order of the steps
  • A request or its reply

The parts: switch one off

1. Clients

Chat widgeta customer asks

2. Services

Assistant servicebuilds the prompt

3. Data, outside

Language modelwrites the answer

The steps in words0 of 3 steps shown

  1. Chat widget to Assistant serviceHTTPS · 3 ms

    A customer asks "How do I reset my password?"

  2. Assistant service to Language modeloutside call · 80 ms

    It sends the question to the model with no extra text.

  3. Assistant service to Chat widgetreply · 20 ms

    The answer goes back. It may be made up.

Why this version
A demo in an afternoon.
Next bottleneck
The model has never seen the company's products. Its answers can be wrong yet sound sure, and they name no sources.

Write path, read path and failures

Each path follows one request through the final design (version 3), one hop at a time.

Write pathA help article changes

  1. Help center
  2. Re-index worker
  3. Embedding model
  4. Search index
  1. Help center to Re-index worker

    An edited article sends a change event.

  2. Re-index worker to Embedding model

    The worker cuts the article into passages and gets a vector for each one.

  3. Re-index worker to Search index

    It replaces the article's old passages with the new ones, along with who may see them.

Read pathAnswer a question

  1. Customer chat
  2. Gateway
  3. Retriever
  4. Reranker
  5. Language model
  6. Guardrails
  1. Customer chat to Gateway

    A customer asks a question. The gateway checks who they are and how many tokens they have left today.

  2. Gateway to Retriever

    The retriever runs a keyword search and a vector search, limited to articles this customer may see.

  3. Retriever to Reranker

    A reranker reads the top 50 passages with the question and keeps the best few.

  4. Reranker to Language model

    The prompt holds the question and those passages. The model starts writing the answer.

  5. Language model to Guardrails

    Guardrails check the answer, for example for personal data or claims no passage supports.

  6. Guardrails to Customer chat

    The answer streams to the customer, with links to the articles it used.

What breaks, and what happens then

  • The main model is slow or down

    What users see
    No first words within the 2-second goal.
    What the design does
    After a time limit, the gateway sends the request to a fallback model.
  • The search finds nothing useful

    What users see
    The model may make up an answer.
    What the design does
    If the best passage scores below a set level, the assistant says it does not know and offers a human agent.
  • An article contains text that gives the model orders

    What users see
    The model may follow it. This is called prompt injection.
    What the design does
    Passages go into the prompt as quoted material, the model has no tools that change accounts, and guardrails check what comes out.
  • One customer sends a flood of questions

    What users see
    Model costs rise for everyone.
    What the design does
    Rate limits and token quotas per customer at the gateway.

6. Deep dives

Latency budget
Streaming hides most of the writing time. The first words appear after three waits. In example figures, search takes about 100 ms, reranking about 100 ms, and the model's first token 0.3 to 2 s. Fewer, better passages cut both the wait and the cost.
Evaluation
Keep a fixed set of real questions with known good answers and run it on every prompt, model or index change. Track groundedness (is every claim supported by a cited passage?), answer rate and hand-off rate, alongside live feedback.

7. Follow-up questions

  • How do you stop one customer seeing another customer's documents? (Filter by tenant inside the search query, not after the answer is written, and test it.)
  • Costs doubled last month. What do you check? (Tokens per answer, cache hit rate, passages per prompt, which model answers which questions, and abuse.)

What it costs

Model calls are the bill, and input tokens are most of it. Send fewer and shorter chunks, cache answers to repeated questions, and use a smaller model for easy ones. The search index is cheap next to that.

Another way to design it

For a small set of help articles, plain keyword search with one model call can be enough. There is no vector index to build or keep fresh. It misses questions that use different words from the article.

8. How answers are judged

A passing answer at Mid level. A complete design with numbers: about 20 questions a second at peak, each needing an embedding, a search and a model call. It explains retrieval-augmented generation and goes deep on one part, such as citations.

How each level is judged
What is judgedJuniorMidSeniorStaff
BreadthHow much of the system does the answer cover?Names the core parts: clients, servers, a database and a cache.Covers the whole main flow, from the request to the stored data and back.Builds a complete design without being led through it.Covers the system, the systems around it and who owns each part.
DepthHow far does it go into the hard parts?Explains what each part does and why it is there.Goes deep on one part, such as the database or the cache.Goes deep on the two or three riskiest parts.Goes deepest where the risk is largest, and explains why the risk is there.
DrivingWho leads the conversation?Follows the interviewer, step by step.Moves forward alone, with an occasional nudge.Leads the conversation from start to finish.Changes the problem when the question asked is not the right one.
Trade-offsAre choices compared and justified?Names more than one option.Says why one option was picked over another.Compares options in detail, with what each one costs.Ties each choice to cost, speed and risk for the business.
Unclear questionsWhat happens when the question is vague?Answers the questions that are asked.Asks questions to make the problem clear.Sets the scope and says what is left out.Questions the assumptions behind the problem itself.
ScopeWhat does it consider beyond the normal path?Covers the normal path, when everything works.Adds what happens when a part fails.Adds growth: what breaks at ten times the load, and the fix.Adds abuse, cost and the daily work of running the system.

Requirements and scope

Strong answer
Before I design, I want to check the scope. Answers must cite sources and hand off to a person when the model is unsure, and each business customer must only see its own documents. Do users need every article searchable at once, or is the newest set enough for now? I will assume first words appear within about 2 seconds.
Weak answer
Customers type a question into the chat widget, and I send it straight to the model for an answer. Since language models are trained on a huge amount of text already, that should cover most product questions.

Shows: Unclear questionsThe difference: A model trained on general text was never trained on this company's own documents, so it can only guess plausible answers. Retrieving real passages first grounds the answer instead.

Estimates

Strong answer
200,000 questions a day is about 2.3 a second on average, rising to the stated 20 at peak. Each needs one embedding, one search and one model call, so peak needs 20 a second of model capacity, not the average. The index is about 40 gigabytes for 5 million chunks, plus about 365 gigabytes a year of conversation logs.
Weak answer
500,000 documents at about 6 kilobytes a vector is about 3 gigabytes for the index, so a single small server holds it comfortably.

Shows: DepthThe difference: The index is built from chunks, not whole documents, and there are about 5 million of those. That is closer to 40 gigabytes, not 3.

Core design

Strong answer
Documents are chunked and embedded offline into a vector index. Retrieval mixes vector and keyword search, filtered to this customer's documents, then a reranker picks the best passages, together taking roughly 100 milliseconds. Streaming then shows first words as soon as the model's first token arrives, roughly 0.3 to 2 seconds later, well before the full answer finishes.
Weak answer
I would retrieve the best matching passages across every customer's documents, then filter out any that are not this customer's before they reach the model.

Shows: DepthThe difference: Passages from another customer already reached retrieval and could still slip into the prompt before the filter runs. Filtering inside the retrieval query is what stops that.

Deep dive

Strong answer
The hard part is knowing whether the system is actually working, since a model can sound confident while it guesses wrong. I would keep a fixed set of real questions with known answers, and run it on every prompt, model or index change. I would track groundedness, whether each claim traces to a cited passage, and the hand-off rate.
Weak answer
I would watch the thumbs up and thumbs down feedback users leave on each answer. If that stays mostly positive, I would treat the system as working well.

Shows: DepthThe difference: Live feedback alone will not catch a regression from a prompt or index change before users see wrong answers. A fixed test set run on every change catches it first.

Failures and trade-offs

Strong answer
If the model is slow or down, I would time out and fall back to a smaller, faster model, or hand off to a person. Since tokens are the main cost, I would cap tokens per customer with a daily quota. I would also alert if cost per answer climbs above the budget.
Weak answer
If the model is slow, I would let the request wait. A right answer that takes longer beats a fast wrong one.

Shows: Trade-offsThe difference: A customer waiting indefinitely for one slow request still costs a connection and tokens, with no answer meanwhile. A timeout with a fallback model or hand-off keeps the product responsive.

We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.

10. Check your design with your own AI

Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.

The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.

See the prompt
You are a system design interviewer. Review my design for the interview problem below.

Problem: Design an AI Support Assistant (RAG)
Answer customers' questions from the company's own help articles and past tickets. Each answer names its sources and stays within a time and cost budget.

What users must be able to do:
- Answer questions in a chat widget using help articles, product docs and resolved tickets.
- Cite the sources of each answer. When unsure, say so and hand the chat to a person.
- Keep each business customer to its own documents, so no customer sees another's files.
- Stream each answer as it is written, a few words at a time.

How well it must work:
- First words within about 2 s, and the full answer within about 10 s.
- A cost per answer within budget. Model tokens are the main cost.
- Quality measured all the time: is each answer backed by its sources, and was the question resolved?
- New or changed articles searchable within minutes.

Numbers to assume:
- 200,000 questions a day, peaks of about 20 per second.
- 500,000 documents split into about 5 million chunks.

Judge my design at the Mid level.
A passing answer at this level: A complete design with numbers: about 20 questions a second at peak, each needing an embedding, a search and a model call. It explains retrieval-augmented generation and goes deep on one part, such as citations.

For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each:
1. Requirements and scope
2. Estimates
3. Core design
4. Deep dive
5. Failures and trade-offs

Then ask me the two follow-up questions an interviewer would ask next.
Do not write a full model answer for me.

My design:
[Describe your parts, how one request moves through them, and why you chose each one.]