Design an AI Search Engine like Perplexity
Understanding the Problem
🌐 What is an AI search engine? An AI search engine answers a question with a written answer instead of a list of links. Behind each answer, it searches the web, reads the most relevant pages, and has a language model write a summary in which every claim is cited to a numbered source. Perplexity is the best-known example; Google's AI Overviews, ChatGPT search and Bing's Copilot answers work in similar ways. The user gets the answer in seconds and can click through to check any part of it.
It's retrieval-augmented generation where the corpus is the whole web and the retrieval happens live, during the request. That brings constraints a private-document RAG System doesn't have: we don't control the content, much of it is spam or out of date, the user expects news from ten minutes ago, and all of it (search, fetching pages, reading them, writing the answer) has to fit in a few seconds.
We won't rebuild a web search engine from scratch here; Web Search and Web Crawler cover the index and the crawl. The question is how to put an LLM on top of web retrieval well.
Functional Requirements
Core Requirements
- Users should be able to ask a question and get a direct answer, streamed in, synthesized from current web sources.
- Each claim in the answer should cite its sources, and the sources should be listed with titles and links.
- Users should be able to ask follow-up questions in the same thread, with the earlier context taken into account.
- Users should be able to run a deeper research mode for complex questions, which searches in several steps and writes a longer report.
Below the line (out of scope)
- Answering from the user's own files (see NotebookLM) or from company apps (see Enterprise Search).
- Accounts, billing, ads and shopping.
- Image and video generation.
Non-Functional Requirements
Ask your interviewer about scale. We'll design for 20M queries a day, with peaks around 700 queries per second and spikes when big news breaks.
Core Requirements
- Users should see the sources within about 1 second and the first words of the answer within about 2 seconds; a full answer should finish within 10 seconds. Research mode can take minutes, as long as it shows progress.
- Answers should be grounded in the cited sources, with no unsupported claims, and should prefer reliable sources over spam.
- Answers about news and recent events should reflect information from the last few minutes to hours, not the model's training cutoff.
- Cost per query must stay low and predictable, since every query costs money in search, fetching and LLM tokens.
- The system should behave well toward publishers: identify itself, follow robots rules and not bypass paywalls.
Below the line (out of scope)
- Multi-language quality tuning and region-specific results.
- Personalization beyond the current thread.
The back-of-the-envelope:
- 20M queries a day is about 230 per second on average, ~700 at peak.
- Each query runs a few search calls and reads maybe 8-10 pages. At 700 QPS, that's 5,000-7,000 page reads per second. At ~50 KB of HTML each, that's around 300 MB per second of inbound fetching if nothing is cached.
- Each answer puts maybe 6-10k tokens of extracted passages into the prompt and writes ~400 tokens. At 700 QPS: about 5M input tokens per second and 280,000 output tokens per second. LLM cost is the largest line item, and it's paid on every query.
- A full web index is billions of pages and a very large fleet to build and run (see Web Search). That's not where most teams start.
Two numbers shape this design. Latency: search, fetching, reading and generating all have to fit in a couple of seconds before the first word appears. Cost: every query pays for search calls, page fetches and thousands of LLM tokens. Most of the good ideas in this problem either save time on the critical path or save tokens.