Menu

Database Isolation Explained: Two Payments at the Same Moment
📰

Database Isolation Explained: Two Payments at the Same Moment

DEV Community: mysql·Dilip V P·4 days ago
#iQn3q7jb
#devtomysql#devto#dev#balance#payment
Long article (1634 words) — no AI summary yet.
Reading 0:00
15s threshold

Alex has one hundred dollars. He pays the pizza shop twenty and the flower shop forty, at the same moment, from one bank account. Both payments say done. He should have forty left. He has sixty, and the bank is twenty dollars short. There was no error anywhere. This article shows why, and three ways to make it safe.

The video tells the same story in five minutes. This is the written version, with the SQL.

One account, one row

Alex's account is one row in MySQL:

CREATE TABLE accounts ( owner VARCHAR ( 64 ) NOT NULL , balance INT NOT NULL , PRIMARY KEY ( owner ) ) ENGINE = InnoDB ;

INSERT INTO accounts VALUES ( 'Alex' , 100 ) ;

Enter fullscreen mode

Exit fullscreen mode

What MySQL gets right: the row lock

First, the case that works.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.