Interview Q&A · questions with model answers

Database Concurrency & Scaling Interview Questions

Part of the study plan for: Data Engineer · Site Reliability Engineer (SRE) · Backend 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 Two customers buy the last item at the same moment and both orders are confirmed. What happened, and how do you prevent it?

    A lost update: both requests read stock = 1, then each wrote back a value computed in application code. Fix it with an atomic conditional update (UPDATE … SET stock = stock - 1 WHERE id = ? AND…

  2. Most asked After a deploy, logs show hundreds of 'deadlock detected' errors per hour on checkout. Walk through how you'd investigate.

    Read the deadlock reports to find the two statements and tables involved, map them to the two code paths, and compare their lock order. Usually a new code path locks the same rows in a different…

  3. Most asked Your service throws 'connection pool exhausted' errors but database CPU is only 20%. What's going on?

    Connections are being held while not doing database work — usually an HTTP call, slow rendering or open-session-in-view inside a transaction. Pool throughput is pool size ÷ hold time, so long holds…

  4. A 20 ms ALTER TABLE caused a multi-minute outage. Explain and prevent it.

    The ALTER needed an exclusive lock and waited behind a long-running query; all later queries on the table queued behind the ALTER. Set lock_timeout (Postgres) / lock_wait_timeout (MySQL) on…

  5. An API's deep pages are slow and a sync job sees duplicate and missing rows. What would you change?

    Replace OFFSET pagination with keyset (cursor) pagination on a unique sort key such as (created_at, id). OFFSET reads and discards rows and shifts when data changes; keyset seeks directly and stays…

  6. You have 14 services autoscaling against one Postgres and hit 'too many clients'. What's the long-term fix?

    Put a transaction-mode pooler (PgBouncer, RDS Proxy) in front, give each service a connection budget with small per-pod pools, and reuse clients in serverless functions.

  7. Your read replicas lag 40 seconds during a nightly import. What do you do?

    Throttle the import (small batches, pause on lag), route freshness-sensitive reads to the primary or lag-aware healthy replicas, and alert on lag. Also check for long queries on replicas delaying…

Was this page helpful?

Report a mistake