Distributed

Lesson 02.4

Optimistic concurrency (versions)

Optimistic concurrency lets work proceed without waiting, then uses a version check to reject an update if someone else changed the data first.

Check nothing changed before you update

A cookie shop's computer shows how many cookies are left. Right now it says 1 🍪. Two workers, Ava and Ben, each get an order at almost the same moment.

Next to the number of cookies, the computer now shows a second number 🏷️: how many times the cookie number has been updated. Workers don't wait for each other. Instead, each worker checks the 🏷️ count again right before updating the number of cookies.

In this lesson you'll

  1. 1Watch the 🏷️ change count on a normal day.
  2. 2Guess what happens when Ben's number is out of date.
  3. 3Compare a quiet moment with one where a worker must start over.