The Lost Update

Talk it through out loud with your AI coach.

The problem

  • easy

Two shop assistants each read that a product has ten in stock, each sell one, and each save nine, so the stock ends up at nine instead of eight. Explain why this happened and two ways to prevent it.

What a strong answer covers

  • The sequence of events that lets one save overwrite another.
  • A way to let the database apply the change itself.
  • Ways to detect or block a competing change.
  • Why a transaction on its own may not be the whole answer.

Common mistake: Assuming that wrapping the code in a transaction automatically makes it safe.

Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.

Practise it out loud