Relational Databases interview questions
100 Backend Engineering practice questions. Read what a strong answer covers, then practise it out loud against the clock.
Practise Relational Databases questionsBeginner
- "Too many connections" errors
- A migration locked the table
- A query got slow as data grew
- Backing up a production database
- Choosing column data types
- Composite indexes and column order
- Database constraints
- Database migrations
- Database normalisation
- Deleted records keep showing up
- Deleting a customer with orders
- Designing tables for an online store
- Duplicate usernames despite a check
- GROUP BY and HAVING
- Half-saved data after an error
- How a database index speeds up queries
- Implementing a money transfer
- NULL in SQL
- Offset pagination is slow on deep pages
- Primary keys and foreign keys
- Reading a query plan
- SQL injection
- Stored procedures: yes or no?
- Subqueries vs CTEs
- Tracking when rows change
- Types of SQL joins
- Using read replicas from application code
- UUID vs auto-increment primary keys
- Views in SQL
- What a database transaction is
- What an ORM is
- Which columns should you index?
- Why relational databases are so common in backends
- Why use a database connection pool
Intermediate
- A counter row causes contention
- Advisory locks
- Case-insensitive unique emails
- Covering indexes
- Data appears then disappears
- Database deadlocks
- Detecting N+1 queries
- Frequent deadlock errors
- Implementing optimistic locking with a version column
- Importing a million rows quickly
- Insert or update in one statement
- Inserts slowing down over time
- Isolation levels and the anomalies they prevent
- Keeping an audit history of changes
- LIKE queries are slow
- Logical vs physical replication
- MVCC and VACUUM in Postgres
- Optimising a slow report query
- ORM loads too much data
- Partial and expression indexes
- Prepared statements
- Query planner statistics
- Reports differ by time zone
- SELECT FOR UPDATE
- Serializable isolation in practice
- Should you use JSON columns?
- Sizing a connection pool
- Stock count goes wrong under load
- Table partitioning in relational databases
- Upgrading a database version
- Using the database as a job queue
- When to denormalise in an OLTP database
- Window functions in backend queries
Experienced
- A migration caused a full outage
- A query suddenly became slow
- Adding a NOT NULL column to a billion-row table
- Analytics query on a replica affects the primary
- Application-level sharding
- B-tree index internals and write costs
- Bad data slipped in without constraints
- Change data capture from Postgres
- Common SQL performance anti-patterns
- Connection storms from serverless functions
- Cross-region read replica for latency
- Database failover from the application's view
- Deleting 500 million old rows
- Enforcing tenant isolation in the database
- Index much larger than the table
- Job queue table becomes a bottleneck
- Keeping a cache in sync with database updates
- Keeping data consistent across services without foreign keys
- ORM can't express a query efficiently
- Preventing double booking with SQL
- Querying deep category trees
- Reporting queries slow down the app
- Restore takes too long
- Row locks vs table locks
- Running out of integer IDs
- Splitting a table without downtime
- Storing sensitive data in the database
- Storing time-series data in a relational database
- Team wants to move from Postgres to MongoDB
- Transaction holding locks during an API call
- Transaction pooling with PgBouncer
- Write skew
- Your single Postgres is reaching its limits