Database Concurrency & Scaling interview question · Most asked

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

Summary

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 inventory rows (buckets or an admission queue); and isolate the endpoint's pool.

Longer Answer

Never hold locks during payment calls. Use a constraint (stock >= 0) as the final guard, load-test with concurrent requests on the same SKUs, and monitor invariants (held + paid ≤ initial stock) live.

Key Points

  • Atomic decrement + idempotency key
  • Reserve → pay → confirm
  • Expiring holds
  • Spread/meter hot rows

Deep dive: Capstone: Never Oversell

More most-asked Database Concurrency & Scaling questions

← All Database Concurrency & Scaling questions