The customer cancels as the restaurant accepts
transcript
A customer taps cancel on their order. At the same moment, the restaurant taps accept. Two threads, one order.
Two calls reach the same order, in the same instant. Each checks the state first. And each sees placed, because neither has changed it yet. Both pass. The customer is refunded, and the kitchen starts cooking. The order ends up as whichever call wrote last.
Without a lock, both calls pass the check, and both think they won. With one lock, one call goes first. Say, the cancel. The customer gets 300 back. The accept then sees cancelled, and is refused. Exactly one call wins.
Check the state. Apply the transition. Work out the refund. Three small parts. All three under one lock. Never split them up. Not even for a moment.
Otherwise two calls both win. Both think they succeeded. A refund paid out, and a meal still being cooked.
Full breakdown in the lecture.