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.

EasyTechnical
41 practiced
Define a covering index and explain how it improves query performance. Given a table users(id int, email text, country text, created_at timestamptz) and the frequent query SELECT email FROM users WHERE country = 'US' AND created_at > '2024-01-01', propose a PostgreSQL index definition that would act as a covering index for this query and explain why it helps.
HardTechnical
56 practiced
Design a high-throughput rate-limiting system for API requests that enforces per-user quotas (for example, 100 requests/minute) with low latency and the ability to handle millions of requests per second. Compare implementing counters in the primary relational database versus Redis (in-memory) and discuss token-bucket algorithms, Lua scripts for atomic operations, TTL-based sliding windows, and consistency/accuracy trade-offs in a distributed environment.
MediumTechnical
74 practiced
A reporting query frequently scans a large fact table producing many temporary files and spilling during sorts/aggregations. Propose strategies at the database configuration level and schema/query level to reduce spills and temporary disk usage: consider work_mem, maintenance_work_mem, parallel_workers, indexes, pre-aggregation, and query rewrite approaches.
MediumSystem Design
54 practiced
For a SaaS multi-tenant application, compare three multi-tenant schema approaches: (a) single shared table with tenant_id column, (b) separate schemas per tenant, and (c) separate databases per tenant. Discuss trade-offs for operational complexity, security/isolation, backup and restore, scaling, and query performance. Provide recommendations for small, medium, and large tenants and a migration path between models.
HardTechnical
53 practiced
An EXPLAIN ANALYZE shows a Bitmap Index Scan followed by a Bitmap Heap Scan producing many random I/Os and slow performance on a frequently-run read query. The table is large but the query only selects two small columns. Describe how you would change schema, indexes, or table clustering to allow index-only scans and reduce random I/O. Include specific PostgreSQL commands (for example, CREATE INDEX ... INCLUDE, CLUSTER) and discuss trade-offs such as maintenance cost and bloat.

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.