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 How do you choose a shard key for a multi-tenant SaaS?

    Pick the entity almost every query and transaction is scoped to — usually the tenant/workspace — and co-locate related tables by it. Use many logical shards on fewer physical databases, and…

  2. Most asked How do you rename a column with zero downtime?

    Expand/contract: add the new column, deploy code that writes both and backfill in batches, switch reads to the new column, and drop the old one only after no running code uses it.

  3. Most asked How do you prevent overselling in a flash sale with 50,000 buyers in the first minute?

    One short transaction per attempt with an atomic conditional decrement and an idempotency key; payment outside the transaction; expiring holds returned by a sweeper; spread or meter the hot…

  4. How would you prevent double-booking a meeting room?

    Make the database reject overlaps: a Postgres exclusion constraint on (room_id WITH =, time range WITH &&), or serialize bookings per room by locking the room row before checking and inserting.

  5. How do you build a reliable job queue on Postgres?

    Claim jobs with SELECT … FOR UPDATE SKIP LOCKED in a short transaction, mark them running with a lease, process outside the transaction, make processing idempotent, and have a sweeper return expired…

  6. How do you retry a transaction safely after a serialization failure or deadlock?

    Retry the whole transaction from the start (re-reading data), only for retryable errors (40001, 40P01, MySQL 1213), with capped attempts and jittered backoff — and keep side effects out of the…

  7. How do you choose the column order of a composite index?

    Equality-filtered columns first, then the range or sort column. (account_id, created_at) serves WHERE account_id = ? ORDER BY created_at DESC without a sort; the reverse order doesn't.

  8. How would you make webhook processing exactly-once from the database's point of view?

    Record each event id in a table with a unique constraint inside the same transaction as the processing (INSERT … ON CONFLICT DO NOTHING RETURNING); if nothing is inserted, the event was already…

  9. How do you delete 90 days of old events every night without hurting production?

    Partition the table by time and drop (or detach) whole old partitions instead of deleting rows; if partitioning isn't possible, delete in small committed batches throttled by replica lag.

  10. How do you generate unique IDs across database shards?

    Use globally unique, ideally time-ordered IDs that don't need coordination: Snowflake-style (timestamp + shard/worker + sequence) or UUIDv7. Encoding the shard lets you route by id.

  11. How do you safely backfill 50 million rows?

    In small committed batches by primary-key range, idempotent (WHERE new_col IS NULL), checkpointed for resume, and throttled on replica lag — run as a monitored background job, not one giant UPDATE.

  12. How do you design user-facing features on top of eventually consistent data like search indexes?

    Give users read-your-writes (show the saved entity from the write response), make propagation visible (pending states), keep views monotonic with versions, and reconcile derived data against the…

Was this page helpful?

Report a mistake