my profile: https://my-profile-personal-nextjs.vercel.app
Github: https://github.com/eslam-cmd
Thanks for visiting my account 😊
Still learning, so corrections are welcome. Follow along if that sounds useful.
Both requests read stock = 1 before either decrements it, so stock ends at -1.
One fix is letting the database decide atomically:
UPDATE products SET stock = stock - 1 WHERE id = 10 AND stock > 0;
Then check rows affected.
Both requests read stock = 1 before either decrements it, so stock ends at -1.
One fix is letting the database decide atomically:
UPDATE products SET stock = stock - 1 WHERE id = 10 AND stock > 0;
Then check rows affected.
Still learning, so corrections are welcome. Follow along if that sounds useful.
Still learning, so corrections are welcome. Follow along if that sounds useful.