Knowledgebase

Preventing Lost Updates Print

  • 0

Concurrent writes to the same record.

WHAT A LOST UPDATE IS

Two transactions reading a value, both modifying it, and one overwriting the other.

WHY IT IS COMMON

Applications read a record, present a form, and save it later.

WHAT THAT PATTERN PRODUCES

Whoever saves last overwrites the other's changes silently.

WHAT PESSIMISTIC LOCKING DOES

Locks the row when read, preventing others until committed.

WHAT IT COSTS

Held locks, and poor behaviour if the user walks away.

WHY THAT MAKES IT UNSUITABLE FOR FORMS

The lock would be held across a human's thinking time.

WHAT OPTIMISTIC LOCKING DOES

Records a version, and checks it has not changed on save.

WHAT HAPPENS ON CONFLICT

The save is rejected, and the user is told.

WHY THAT IS USUALLY CORRECT

It surfaces the conflict rather than silently discarding work.

WHAT TO IMPLEMENT

A version column, incremented on every update An update condition matching the version read Handling of zero rows affected

WHAT ZERO ROWS AFFECTED MEANS

Someone else changed it first.

WHAT TO SHOW THE USER

That the record changed, and what to do.

WHAT TO AVOID

Updating every column from a form.

WHY

It overwrites fields the user never saw.

WHAT TO DO INSTEAD

Update only what changed.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot