Interview Q&A · questions with model answers

Databases & Transactions Interview Questions

Part of the study plan for: Backend Engineer · Full Stack Engineer · Data Engineer

Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.

  1. Most asked How do you choose between SQL and NoSQL databases?

    Choose relational (PostgreSQL, MySQL) for structured data with relationships, transactions and flexible querying; choose NoSQL for specific access patterns: document stores (MongoDB) for flexible…

  2. Most asked How do you run schema migrations without downtime?

    Use the expand/contract pattern: first make backward-compatible additions (new nullable columns, new tables), deploy code that writes to both or reads the new shape, backfill data in batches, switch…

  3. What causes deadlocks and how do you handle them?

    Deadlocks occur when transactions hold locks the others need, in a cycle (A locks row 1 then wants row 2; B locks row 2 then wants row 1). Databases detect them and abort one transaction.

  4. How do you read a query plan and optimize a slow query?

    Run EXPLAIN (ANALYZE, BUFFERS) to see the actual plan: look for sequential scans on large tables, row estimate vs actual mismatches, expensive sorts or hash joins spilling to disk, and nested loops…

  5. How should you back up and restore databases?

    Combine regular full backups with continuous WAL/binlog archiving for point-in-time recovery, store backups in a separate account/region, encrypt them, define RPO/RTO targets, and regularly test…

  6. How should you test database code?

    Run integration tests against the real database engine (via Testcontainers or a disposable instance), apply migrations in CI, isolate tests with transactions rolled back after each test or fresh…

Was this page helpful?

Report a mistake