Home / AI Architecture & System Design / AI System Design

AI System DesignSeniorQuestion 17 of 20

Design a real-time answer engine like Perplexity that answers questions from the live web with citations.

30-second answer

Pipeline with per-stage budgets: a small model rewrites the question into searches and a freshness class (~120 ms); our fresh index and a search API run in parallel (~250 ms); pages come from a snapshot cache or a live fetch with a 700 ms timeout; a cross-encoder reranks ~60 passages with a per-domain diversity limit; sources show at ~1.1 s. The answer model writes only from numbered passages, and an entailment model checks each cited sentence. ~3 cents per query, so cache answers by freshness class and route simple lookups to cheaper models. Buy coverage (search API), build freshness (own index for news and popular domains).

Try answering out loud before reading on. The walkthrough below is paced for a 40-minute interview round.

New to these terms? 11 terms on this page are explained in the glossary

0–5 min Functional requirements

An answer engine is RAG where the corpus is the live web. The hard parts are freshness, latency across several network hops, and making sure every sentence is backed by the source it cites.

You Is this a product like Perplexity: a question in, a written answer with numbered citations out?

Interviewer Yes. Users should see sources quickly, then the answer streaming.

You Do we run our own web index, or call a search API?

Interviewer Your call. Justify it.

You Follow-up questions in the same thread?

Interviewer Yes.

You How fresh must it be? Breaking news, or is a day old fine?

Interviewer News within minutes matters for some queries.

# Functional requirement Why it matters
F1 Answer a natural-language question with a written answer The product
F2 Every factual sentence cites a numbered source; sources listed and clickable Trust; lets users verify
F3 Fresh results for time-sensitive questions (news, prices, releases) The reason to use this over a plain chatbot
F4 Follow-up questions use the thread's context "How does that compare to …?"
F5 Show sources before the answer finishes Perceived speed and transparency
F6 Say so when sources disagree or don't answer the question Avoid confident wrong answers

Out of scope: image and video answers, shopping checkout, user accounts beyond history.

5–10 min Non-functional requirements and estimates

Requirement Target What it forces
Sources shown ≤ 1.2 s p95 Parallel search, page-snapshot cache, strict fetch timeouts
First answer token ≤ 2 s p95 Small model for query rewriting; reranking budget ~100 ms
Freshness News indexed within ~10 min; popular pages within a day Tiered crawling; live fetch for top results
Citation accuracy ≥ 95% of cited sentences supported by the cited passage Passage-level citations; a verification step
Availability 99.9%; degrade to fewer sources rather than fail Timeouts and partial results everywhere
Cost A few cents per query at most Caching, model routing, short contexts

Back-of-envelope estimates:

  • Traffic: 20M queries/day ≈ 230/s average; ~700/s at peak (3×).
  • Per query: 2–3 search queries; ~25 candidate URLs; ~8 pages read; ~60 candidate passages reranked; ~8 passages (~4,000 tokens) in the prompt. Prompt ~5,500 tokens with instructions and thread; answer ~400 tokens.
  • Cost per query at illustrative prices ($3 per million input tokens and $15 per million output for the answer model):
answer model input   5,500 × $3/M      ≈ $0.0165
answer model output    400 × $15/M     ≈ $0.0060
query rewrite (small model)            ≈ $0.0001
rerank (cross-encoder on GPU)          ≈ $0.0005
search API calls (if bought)           ≈ $0.0050
total                                  ≈ $0.028
  • At 20M queries/day that's ~$560k/day, so caching repeated questions and routing simple ones to a cheaper model are worth a lot.
  • Page fetches: 700 queries/s × 8 pages = 5,600 page reads/s at peak. Most must come from a snapshot cache; live fetching all of them would be slow and impolite to websites.

10–18 min High-level design

You Online, five stages run in sequence, each with a time budget: understand the query, search, read pages, rank passages, generate with citations. Offline, a crawler keeps a page index and snapshot cache fresh at different rates for different kinds of sites.

Scroll sideways to see the whole diagram.

Real-time web answer engine (Perplexity-style)Components: Crawler + indexer (tiered recrawl · RSS); Fresh index (news · popular domains); Snapshot cache (clean page text); User (question · follow-ups); Query rewriter (small model · freshness); Search (own index + search API); Page reader (cache · live fetch); Reranker (cross-encoder); Citation verifier (entailment per sentence); Answer LLM (numbered passages). Flow: Crawler + indexer to Fresh index; Crawler + indexer to Snapshot cache; Fresh index to Search; Snapshot cache to Page reader; User to Query rewriter; Query rewriter to Search; Search to Page reader; Page reader to Reranker; Reranker to Answer LLM (top 8 passages); Answer LLM to Citation verifier; Citation verifier to User (sources, then cited answer).Crawler + indexertiered recrawl · RSSFresh indexnews · popular domainsSnapshot cacheclean page textUserquestion · follow-upsQuery rewritersmall model · freshnessSearchown index + search APIPage readercache · live fetchRerankercross-encoderCitation verifierentailment per sentenceAnswer LLMnumbered passagestop 8 passagessources, then cited answer
Real-time web answer engine (Perplexity-style). Online: a small model rewrites the question into searches; our fresh index and a search API run in parallel; pages come from a snapshot cache or a time-boxed live fetch; a cross-encoder picks passages with a diversity limit; the answer model writes from numbered passages and an entailment check verifies each citation. Offline: a tiered crawler keeps the index and snapshots fresh.

Components:

  • Query understanding: a small, fast model turns the question (plus thread context) into 1–3 standalone search queries, a freshness class (breaking, recent, evergreen) and an intent.
  • Search: queries our own index (fresh news and popular domains) and, for coverage, a commercial web search API, in parallel; results are merged and deduplicated.
  • Page reader: gets page text from the snapshot cache, or live-fetches with a hard timeout (~700 ms) and extracts the main content (boilerplate removal), then splits it into passages.
  • Reranker: a cross-encoder scores ~60 passages against the query; selection also enforces source diversity and quality.
  • Answer generator: a large model with instructions to answer only from the numbered passages, cite each claim and say when sources conflict or are missing.
  • Citation verifier: checks each cited sentence against its passage with a small entailment model; unsupported citations are removed and logged.
  • Crawler and indexer (offline): tiered recrawl schedules, sitemaps and RSS for news, page snapshots, embeddings and keyword index.
  • Caches: answers (by normalized query and freshness class), search results, and page snapshots.

One query:

Scroll sideways to see the whole diagram.

One question through the answer engineUser → Orchestrator: question; Orchestrator: rewrite → 3 queries; Orchestrator → Search + pages: search index + API; Search + pages → Orchestrator: 24 URLs · 250 ms; Orchestrator → Search + pages: read top 8 pages; Search + pages → Orchestrator: 58 passages · 600 ms; Orchestrator → Reranker: score 58 passages; Reranker → Orchestrator: top 8, ≤ 2 per domain; Orchestrator → User: sources at ~1.1 s; Orchestrator → Answer LLM: prompt with [1]–[8]; Answer LLM → Orchestrator: cited answer stream; Orchestrator: verify each citation; Orchestrator → User: answer from ~1.6 s.UserOrchestratorSearch + pagesRerankerAnswer LLMquestionrewrite → 3 queriessearch index + API24 URLs · 250 msread top 8 pages58 passages · 600 msscore 58 passagestop 8, ≤ 2 per domainsources at ~1.1 sprompt with [1]–[8]cited answer streamverify each citationanswer from ~1.6 s
One question through the answer engine. Each stage has a time budget and returns partial results when it runs out. Sources are sent to the user as soon as reranking finishes, about a second in; the answer streams from about 1.6 s and each citation is checked as it arrives.

API sketch:

POST /v1/threads/{id}/ask  { question }
→ SSE events: status "searching" | sources [{n, title, url, snippet}] | delta "…" | citations_verified | done

How it works: a worked example

A study aid: one question traced through the pipeline with timings. The product is fictional.

The question. "Is the Voltra X2 e-bike's range really 120 km?" The bike was announced yesterday.

1. Query understanding (~120 ms). The small model returns:

{ "intent": "verify_product_claim",
  "freshness": "recent",
  "queries": ["Voltra X2 range test", "Voltra X2 battery range review", "Voltra X2 specifications 120 km"] }

recent means results from the last week get a ranking boost and the answer cache TTL will be short.

2. Search (~250 ms, in parallel). Our news index returns 9 hits (the launch was crawled through a tech site's RSS feed 40 minutes after publication); the search API returns 20. After merging and removing duplicates and syndicated copies: 24 URLs.

3. Read pages (~600 ms). A first-pass score on titles and snippets picks the top 8 URLs. Five are in the snapshot cache. Three are fetched live in parallel with a 700 ms timeout; one forum page doesn't answer in time and is skipped. Seven pages are cleaned and split into 58 passages of ~150–300 tokens each.

4. Rerank (~80 ms). The cross-encoder scores all 58 passages. Selection keeps the top passages with at most 2 per domain and drops a known spam domain:

[1] voltra.com/x2         "…range of up to 120 km in Eco mode…"                      score 0.91
[2] voltra.com/x2/specs   "…battery 625 Wh … tested per EN 15194 …"                   score 0.84
[3] ebikereview.example   "…our ride test: 84 km at assist level 3, rider 80 kg…"    score 0.88
[4] technews.example      "…Voltra claims 120 km; rivals quote 90–100 km…"            score 0.79
… 4 more

5. Sources shown (~1.1 s after the question). The sources event goes out. The user sees eight source cards while the answer is being generated.

6. Generation. Prompt: instructions (~900 tokens), the 8 numbered passages (~3,900 tokens), the question. The first token arrives at ~1.6 s. Output:

Voltra quotes up to 120 km, but that figure is for the lowest assist mode [1][2]. The first independent test got 84 km at assist level 3 with an 80 kg rider [3]. Claims of 90–100 km are typical for rivals with similar batteries [4], so expect well under 120 km in mixed riding.

7. Citation verification (~30 ms per sentence, in parallel with streaming). Each sentence is checked against the passages it cites. Sentence 3 cites [4], and passage [4] supports the "90–100 km" part. All pass. Had a sentence cited a passage that doesn't support it, the marker would be removed and the event logged for evaluation.

8. Caching. The answer is cached under the normalized query with a 30-minute TTL (freshness recent). Page snapshots fetched live are added to the snapshot cache.

9. Follow-up. The user asks "How does that compare to the Rivo S?" Query understanding rewrites it with the thread context into "Voltra X2 vs Rivo S range" and "Rivo S range test". The pipeline runs again; passages from the first answer that are still relevant can be reused.

Where each piece runs:

Component Runs as Example technology If it fails
Query understanding Small model service 8B model on GPUs, or a hosted small model Use the raw question as the search query
Search Own index + external API OpenSearch/Vespa, plus Bing/Brave-style APIs Use whichever side answers; fewer sources
Page reader Fetch workers + snapshot store Headless fetchers, main-text extraction, object storage Use snippets only; say sources are limited
Reranker GPU service Cross-encoder (e.g. a BGE/MiniLM-class reranker) Use search order
Answer model Hosted or self-hosted LLM Large model with long context Fallback model; or show sources without an answer
Citation verifier Small model service NLI/entailment model Skip verification, flag for offline review
Crawler/indexer Batch and streaming jobs Crawl frontier, Kafka, index builders Freshness degrades; the API covers gaps

18–32 min Deep dive

You I'd go deeper on freshness and the index, the latency budget, citation quality, and cost.

Deep dive 1 · Own index vs search API, and freshness

  • Buy coverage, build freshness. A full web index is billions of pages and a large team. Start with a commercial search API for breadth and build your own index for what needs freshness or quality control: news, popular domains, documentation sites.
  • Tiered crawling: news sites through RSS and sitemaps every few minutes; popular pages daily; the long tail weekly or monthly. Prioritize recrawls by how often a page changes and how often it's used in answers.
  • Snapshots: store cleaned page text with its fetch time. The answer can say "as of 10:42 UTC" and the snapshot keeps citations stable even if the page changes.
  • Respect sites: honour robots.txt, rate-limit per domain, identify the crawler.

Deep dive 2 · Holding the latency budget

query understanding    120 ms   small model, short output
search                 250 ms   parallel queries, 300 ms timeout
read pages             600 ms   cache first; live fetch with 700 ms timeout, take what arrives
rerank                  80 ms   ~60 passages, batched on GPU
sources shown        ~1.1 s
LLM time to first token ~500 ms
first answer token   ~1.6 s
  • Every stage has a timeout and a partial result. Five sources on time beat eight sources late.
  • Overlap stages: start fetching the first search results before the slower search call returns; start reranking as passages arrive.
  • Skip stages when possible: cached answers for repeated questions; for evergreen questions, skip live fetch and use snapshots only.

Deep dive 3 · Citation quality and hallucination

  • Cite passages, not pages. The model sees numbered passages, so a citation points to specific text that can be checked and highlighted.
  • Prompt rules: answer only from the passages; cite after each claim; if passages conflict, say so and cite both; if nothing answers the question, say that.
  • Verification: an entailment model checks each (sentence, cited passage) pair. Track the unsupported rate per model and prompt version; it's the key quality metric along with answer helpfulness.
  • Source quality: spam and content-farm detection, domain reputation, and diversity limits so one site can't dominate.
  • Evaluation set: questions with known answers, including recent events, conflicting sources and unanswerable questions, graded for correctness and citation support.

Deep dive 4 · Cost

  • Answer cache: many people ask the same thing about the same news. Cache by normalized query plus freshness class, with TTLs from minutes (breaking) to a day (evergreen).
  • Model routing: simple factual lookups ("capital of Peru", "time in Tokyo") go to a small model or a direct answer from structured data; reasoning and comparisons go to the large model.
  • Fewer, better passages: reranking well means 6–8 passages suffice; doubling context doubles input cost.
  • Own index vs API: API calls are a fixed cost per query; the own index is a fixed cost per month. Shift traffic to the own index for the domains it covers well.

32–37 min Trade-offs

Decision Chosen Alternative Why
Index Search API for breadth + own index for fresh/popular domains Own full web index Months to build; buy coverage, build where freshness matters
Page content Snapshot cache + live fetch with timeout Always live fetch Latency and politeness; live fetch only for fresh or uncached pages
Citation granularity Passages Whole pages Verifiable and highlightable
Verification Entailment check per sentence, in parallel with streaming None, or a second LLM pass after the answer Catches unsupported citations without adding latency
Latency vs completeness Strict stage timeouts, partial results Wait for all sources Users prefer a fast answer with five sources
Routing Small model or structured data for simple lookups Large model for everything Cost, latency

Build first: query rewrite, search API, live fetch with extraction, reranker, cited answer. Then snapshot cache and own news index, citation verification, answer caching and routing.

37–40 min Wrap-up and likely follow-ups

Close with: "A query is rewritten into standalone searches, run against a bought search API and our own fresh index in parallel. Pages come from a snapshot cache or a time-boxed live fetch, passages are reranked with a diversity limit, and sources are on screen in about a second. The model answers only from numbered passages, and each cited sentence is checked by an entailment model. Strict per-stage timeouts, answer caching and model routing hold latency and cost."

Likely follow-ups:

  • How do you handle a question that needs many steps of research? A "deep research" mode: an agent loop that plans sub-questions, searches iteratively and writes a longer report, run asynchronously with progress events.
  • What about paywalled or blocked sites? Use only what's accessible and licensed; show that a source exists without quoting it.
  • How do you stop SEO spam from poisoning answers? Domain reputation, spam classifiers, diversity limits, and cross-checking claims across independent sources.

Further reading

What interviewers listen for

  • A latency budget per stage, with timeouts and partial results.
  • A clear build-vs-buy decision on the index, driven by freshness.
  • Passage-level citations and a way to verify them.
  • Cost per query worked out, and caching and routing as levers.

Red flags

  • "Just call a search API and paste the top pages into the prompt."
  • No timeouts on page fetches.
  • Citations that can't be checked, or no plan for conflicting sources.
  • Ignoring that the answer cache must expire based on freshness.

Discussion

Help us improve our content — give feedback. Spotted an error, have a better explanation, or got asked a follow-up in a real interview? Share it here.