Description:
Two buyers grab the same last ticket and your database lets both win. This video shows exactly why a plain BEGIN transaction with SELECT then UPDATE fails: a normal SELECT reads the row but never locks it, so both buyers read remaining = 1 and both sell. Then you'll see the one-line fix, SELECT remaining FROM tickets WHERE id = 1 FOR UPDATE, which locks the matched row so the second buyer is forced to wait until the first commits. When it finally reads remaining = 0, it's correctly rejected and no ticket is ever oversold. A clear, concrete walkthrough of row locking and race conditions in SQL.
#sql #database #concurrency #raceconditions #backend #postgres
#systemdesign #shorts
#systemdesign #shorts
Share this link via
Or copy link























