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.

MediumSystem Design
45 practiced
Design a sharding strategy for a multi-tenant SaaS application with tenants ranging from 10 users to 10 million users. Requirements: online tenant onboarding, ability to move hot tenants off a shard, minimize cross-shard joins, and support global backups. Describe shard key choices, metadata management, tenant placement logic, and how you'd handle resharding for growth.
MediumSystem Design
48 practiced
Design an audit/logging schema to record schema changes (DDL) across multiple database instances for compliance. Requirements: who made change, before/after DDL, timestamp, affected objects, and ability to replay DDL in a dry-run environment. Discuss storage choices and how to protect against tampering.
MediumTechnical
43 practiced
You are asked to compress cold archival tables to save storage and also keep them queryable for occasional reports. Compare row-store compression, columnar formats (Parquet/ORC), and DB-native compression. Describe ETL approach to convert, query implications, and how to keep small ad-hoc queries responsive.
MediumTechnical
55 practiced
You inherit an application using an ORM (e.g., Hibernate / ActiveRecord) that generates many N+1 queries and slow bulk operations. Provide a plan to find, measure, and fix N+1 problems. Include code-level fixes (eager loading, batch fetching), database-level fixes (indexes, temp tables), and regression testing strategies.
HardTechnical
42 practiced
Write SQL to compute, per user, their most recent N activity timestamps without using window functions (assume DB lacks them). Table: activities(id PK, user_id, occurred_at TIMESTAMP). Provide an efficient approach that works for large datasets and explain trade-offs compared to window-based solutions.

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.