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 Database CPU is at 85%. How do you decide what to optimise before buying a bigger server?

    Rank statements by total time (calls × mean) using pg_stat_statements or performance_schema digests, fix the top entries (indexes, N+1, pagination), and verify with EXPLAIN ANALYZE — usually far…

  2. Most asked A user saves their profile and the next page shows the old data. Reads go to replicas. How do you fix it?

    Provide read-your-writes: route that user's reads to the primary for a window after a write, or record the primary's LSN/GTID after the write and only read from replicas that have replayed past it.

  3. Most asked An order is saved but the 'OrderPlaced' event sometimes never reaches Kafka. How do you fix it?

    Use the transactional outbox: insert the event into an outbox table in the same transaction as the order, and publish it via a relay or CDC (Debezium). Consumers dedupe because delivery is at least…

  4. Most asked A Spring @Transactional method threw an exception but the data was still saved. What are the likely causes?

    Either the method wasn't actually transactional (self-invocation bypasses the proxy, or the method isn't public on a Spring bean) or the exception was a checked exception, which commits by default.…

  5. Scale a read-heavy product catalog 100× — where do you start?

    Measure and fix queries first (N+1, indexes, keyset pagination), then cache hot shared content at the CDN and in Redis with invalidation, add replicas sized for cache misses, and build read models…

  6. Explain write skew with a real example and how to prevent it.

    Two transactions read overlapping data, each decides it may proceed, and each writes a different row — together breaking a rule. Example: two doctors each see two on call and both go off call.…

  7. A customer has two active subscriptions created 40 ms apart. How do you make that impossible?

    Add a partial unique index (one active subscription per customer) and treat the violation as 'already subscribed'. Check-then-insert can't be made safe in application code because there's no row to…

  8. A viral post's like counter makes requests slow. How do you handle hot rows?

    Every update serializes on one row lock, capping throughput at roughly one over the lock hold time. Spread writes (sharded counters), defer them (append likes and aggregate asynchronously), or move…

  9. A scheduled job runs on every app instance and double-bills customers. How do you fix it?

    Coordinate instances with a lock (Postgres pg_try_advisory_lock, MySQL GET_LOCK, ShedLock, Laravel onOneServer) so only one runs it — and make billing idempotent per customer and period as a safety…

  10. A dashboard aggregates years of data on every view. How would you speed it up?

    Precompute: a materialized view refreshed periodically (CONCURRENTLY), a summary table updated in the write transaction, or an event-driven read model — chosen by how fresh the numbers must be.

Was this page helpful?

Report a mistake