InterviewStack.io LogoInterviewStack.io

Database Design and Query Optimization Questions

Principles of database schema design and performance optimization including relational and non relational trade offs, normalization and denormalization, indexing strategies and index types, clustered and non clustered indexes, query execution plans, common table expressions for readable complex queries, detecting missing or redundant indexes, sharding and partitioning strategies, and consistency and availability trade offs. Candidates should demonstrate knowledge of optimizing reads and writes, diagnosing slow queries, and selecting the appropriate database model for scale and consistency requirements.

MediumTechnical
54 practiced
Given this SQL (PostgreSQL) snippet, propose indexes and explain why:
SELECT p.id, p.titleFROM posts pJOIN post_tags pt ON pt.post_id = p.idJOIN tags t ON t.id = pt.tag_idWHERE t.slug = 'backend' AND p.published = trueORDER BY p.published_at DESCLIMIT 20;
State exact indexes you would create and why.
MediumTechnical
84 practiced
You need to speed up an analytics dashboard that frequently runs complex JOINs across large tables. Discuss whether to use materialized views, summary/aggregate tables, or an OLAP store (columnar DB). For each option list the impact on freshness, storage, complexity, and query latency.
EasyTechnical
70 practiced
You see a slow SELECT in production. Describe the steps you would take to diagnose the issue using EXPLAIN/EXPLAIN ANALYZE (or the equivalent), what parts of the plan you inspect first, and what quick changes you might try to improve the query latency without changing application code.
EasyTechnical
75 practiced
Given two scenarios, choose between SQL (relational) and a NoSQL (document or key-value) database: (A) Shopping-cart session store with frequent short-lived updates and high write throughput; (B) User profile storage with complex relational queries and ACID requirements. Justify your choices for each and mention caching options you might add.
HardTechnical
51 practiced
Given this SQL (Postgres) query that uses a correlated subquery and is slow for 1M rows, rewrite it to be performant using joins, CTEs, or window functions. Explain why your rewrite is faster and what indexes you'd add.
Original:SELECT u.id, (SELECT COUNT(*) FROM orders o WHERE o.user_id = u.id AND o.created_at > now() - interval '30 days') AS recent_ordersFROM users u;

Unlock Full Question Bank

Get access to hundreds of Database Design and Query Optimization interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.