Why two browser tabs silently overwrote each other, and how version columns and ETags fix it
A developer testing an admin panel found that editing the same product in two tabs caused one change to vanish with no error or log entry. The cause is a lost update: each form saved every field, including stale values, through the ORM's default last-write-wins behavior. Database transactions cannot prevent this when the read and the save happen in separate HTTP requests, since each transaction is individually valid. The proposed fix is optimistic concurrency control, using an integer version column checked in the UPDATE's WHERE clause and exposed to clients through ETag and If-Match headers. A mismatch returns a 412 or 428 response, letting the user review changes and decide whether to reload or overwrite. Counters and inventory can skip this approach by doing atomic arithmetic in SQL.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in