Hey there,
Two requests read the same row, change it and write it back. The last write wins, and one update is gone without an error. That's Question 2.22 in The Senior JavaScript Interview, tagged Senior.
Calling it a race condition is the easy part. The senior answer checks each layer where it can happen:
In the UI, abort stale requests with AbortController, so only the newest result reaches the screen. That fixes only the screen. The server can still apply the old write.
In one Node process, a mutex per row around the read and the write makes them run one at a time. It doesn't stop a second instance. Across instances, lock the row with SELECT ... FOR UPDATE, with the read and the write in one short transaction on one connection.
In the database, skip the read-modify-write in app code. Use an atomic update like UPDATE ... SET n = n + 1. Or add a version column, bump it in the SET and check the value you read in the WHERE clause. If 0 rows change, re-read, recompute and retry.
The trap is the mutex. It looks like a fix until the second instance starts.
I'm not running a separate Black Friday sale. The launch price is my Black Friday price, and it ends on Monday 30 November at 23:59 Pacific time, which is 09:59 on Tuesday in Sofia. Until then, Standard is $79 and Premium is $149, plus VAT where it applies. After that, they go to $119 and $229.
What you get:
660+ questions and architecture scenarios on React, Node.js, TypeScript and system design, each tagged Junior, Mid or Senior.
The course on petarivanov.tech, in a reader that hides each answer until you've given your own and keeps count of what you've answered, plus an EPUB.
With Premium, Part 6 on the interview itself and the Complete Packages of The Conscious React and The Conscious Node.
Get the course at the launch price
There's a 30-day money-back guarantee. Reply to your receipt for a full refund.
If you already bought the course, thank you, and you can skip this one.
Petar

