Verified Jobs Live
SQL & Relational Databases Medium Level ~3 min read

Two transactions both see one seat remaining and both sell it. How can the database prevent overselling?

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

Make the availability check and decrement part of an atomic conditional update, such as updating only when remaining is greater than zero, and confirm that exactly one row was affected. Create the reservation in the same transaction and roll back if another required step fails. Row locking or an appropriate serializable transaction can also work, with deadlock or serialization-failure retry handling. A prior SELECT followed by an unprotected UPDATE is vulnerable to races. Define cancellation and expiration behavior so inventory is restored consistently.