# sql & databases
// [27] real interview questions. Answers and sources live in the practice app.
practice this topic- Explain the ACID properties of database transactions with concrete examples.(junior)
- What is the N+1 query problem, how do you detect it, and how do you solve it?(mid)
- What are database indexes, how do they improve query performance, and why might the planner not use your index?(mid)
- How would you find the most expensive queries in a running application?(mid)
- What is database normalization, and is it always needed?(mid)
- What is denormalization, and when would you use it?(mid)
- Why do databases treat NULL as such a special case?(mid)
- How would you manage database schema migrations in a team and in production?(mid)
- How would you migrate an application from one database to another, for example from MySQL to PostgreSQL, with minimal downtime?(senior)
- How is lazy loading achieved in ORMs? When is it useful, and what are its pitfalls?(mid)
- Explain the CAP theorem. What does it actually force you to choose, and what do CP and AP look like in real systems?(senior)
- What is eventual consistency, and how do you design an application to live with it?(mid)
- When would you use a document database like MongoDB instead of a relational database like PostgreSQL?(mid)
- What are the pros and cons of holding domain logic in stored procedures?(senior)
- The system you're working on doesn't support transactions. How would you implement transaction-like behavior from scratch?(senior)
- Why are long-lived distributed transactions discouraged in service architectures, and how do sagas with compensations replace them?(senior)
- What are window functions, and what's the difference between ROW_NUMBER, RANK, and DENSE_RANK?(mid)
- Write the classic 'top N per group' query — the 3 most recent orders per customer. Why is it awkward without window functions?(mid)
- In what order does SQL logically evaluate a query, and why can't you use a SELECT alias in WHERE?(junior)
- Subquery vs JOIN — when do you use each, and what's the danger with correlated subqueries?(mid)
- How does MVCC let readers avoid blocking writers, and what does it cost in PostgreSQL?(senior)
- Walk through the transaction isolation levels: which anomalies does each allow, and why doesn't everyone just run SERIALIZABLE?(senior)
- Two of your transactions deadlock every night. How do deadlocks happen, and how do you fix and prevent them?(mid)
- Why does every serious backend use database connection pooling, and how do you size the pool?(mid)
- You add read replicas and users start complaining their just-created post disappears on refresh. What's happening and what are the fixes?(mid)
- Sharding a database: when do you reach for it, how do you pick a shard key, and what breaks?(senior)
- You scan a QR code at a cafe to pay; it works once and can't be replayed, and if your connection hiccups and the app resends, you're still charged only once. Design the QR-payment backend so a scan is single-use and safe to retry.(mid)