At Discord scale, product analytics queries often run against very large event tables such as message sends, session starts, or notification deliveries. A query that works on a small dataset can time out once the table reaches billions of rows.
You are asked to explain how you would optimize a PostgreSQL query that is timing out on a billion-row table. Walk through how you would diagnose the bottleneck, what parts of the SQL you would inspect first, and how you would improve the query itself before proposing broader table or infrastructure changes. You should also explain how joins, filters, aggregations, and date logic can affect performance on large Discord event datasets.
The interviewer expects a practical, SQL-focused answer rather than a generic database lecture. You should cover query rewrites, indexing strategy, partitioning, and how you would validate that the optimized version is actually better.