Lesson 02.1
Read-then-write race
A read-then-write race happens when concurrent requests read the same old state and act on it before either sees the other’s change.
Two workers, one last cookie
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.
Each worker handles an order on a separate checkout page. The page keeps the cookie count from when the order started; it does not refresh while the worker finishes the sale.
Can the shop end up selling a cookie it doesn't have?
In this lesson you'll
- 1Watch a normal sale, one step at a time.
- 2Guess what goes wrong when both workers are quick.
- 3Make one run safe by moving the steps around.