Library
9 min read

Optimistic vs pessimistic locking

Two people open the same Google Sheet cell at the same moment and type different numbers. Two ticket agents read "1 seat left" and both sell it. The problem has a name, the lost update: both read the same starting value, both write a new value based on it, and the second write silently erases the first.

There are two ways to stop it. Pessimistic locking assumes a conflict will happen, so it locks the row before reading and makes everyone else wait. Optimistic locking assumes a conflict probably will not happen, so nobody waits; instead, every write checks that the row has not changed since it was read, and fails if it has.

Your answer

BookMyShow at 10:00 am when a Coldplay concert opens: 500,000 people trying to grab the same few thousand seats. Would you let everyone read freely and detect clashes on save, or lock each seat as soon as someone looks at it? What goes wrong with each?

The lost update#

1/4 read seat 14C: available