Write Skew: The Anomaly the SQL Standard Forgot 0 ▲ Luminousmen Blog - Python, Data Engineering & Machine Learning 57 minutes ago · Tech · hide · 0 comments A family credit account had a limit: $1000 a month, shared across both cards. The banking system enforced this the obvious way. Before every purchase, count how much has already been spent across both cards combined. If the new purchase fits under the remaining limit, allow it. BEGIN; SELECT sum(balance_used) FROM cards WHERE account_id = 7; -- returns 0, so a $700 purchase fits under the $1000 limit UPDATE cards SET balance_used = balance_used + 700 WHERE card_id = 1; COMMIT; Then imagine that both cardholders bought something for $700 at the same exact minute, each on their own card. Neither purchase had committed yet when the other one ran its check, so both transactions read the account's spending as $0. Both concluded $700 fits under the $1000 limit, so it's safe. Both committed. $1400 went through on a $1000 limit — the code did exactly what it was written to do, and the limit got violated anyway. Nobody's rules say w No comments yet. Log in to reply on the Fediverse. Comments will appear here.