Skip to main content

Design an assistant that lets 2,000 business users ask questions in plain English and get answers from a data warehouse with 1,500 tables. Wrong numbers are worse than no answer.

System design · Pro 2

Short answer

Clarify users, scope and how correctness is judged. Retrieve only the relevant tables, column descriptions and metric definitions into the prompt, generate SQL, validate it, and run it read-only with the user's own permissions, row limits and timeouts. Show the SQL and assumptions, ask when the question is ambiguous, and test on question and SQL pairs.

Deeper answer

1,500 tables cannot go in a prompt, and raw schemas rarely explain what "active customer" or "revenue" means. So start with a curated scope and a semantic layer: agreed metric definitions, table and column descriptions, and join paths.

Flow: the question is matched to relevant tables and metrics with retrieval over that metadata, plus a few similar verified question and SQL examples. The model writes SQL in the warehouse dialect. A validator parses it, allows only SELECT, checks tables and columns exist, and estimates cost. The query runs on a read-only role with the user's own row and column permissions, a row limit and a timeout. The answer shows the result, the SQL, and a plain statement of the filters and date range used.

Trade-offs: generating against a semantic layer is more reliable than against raw tables, but covers fewer questions. The real danger is SQL that runs and gives a wrong number through a bad join or a wrong definition. So ask a clarifying question when terms are ambiguous. Evaluate by comparing query results with a reference set, not SQL text, and track user corrections.

What a strong answer covers

Answer it out loud in the mock interview about 2.5 min

Follow-ups to expect

Common mistakes

Learn it

The design interview

Practice System design questions

More on this topic

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.