~learn.
0:00 / 1:25
W05 · Consistency and coordination

One item left. Two buyers. You sold both.

transcript

One item left in stock. Two people click Buy. You sell both. Your inventory says minus one.

The database says 1. The cache says 1. User A clicks Buy, and sees 1 in stock. A tenth of a second later, User B clicks Buy. Also sees 1. A's order goes through. Stock: zero. Then B's goes through too. Stock: minus one. You sold an item you don't have.

Now move 100 dollars from Account A to Account B. Debit A. Done. Credit B. Failed. Service B is down. The money has simply disappeared. One database would just roll back. Across microservices? There's no rollback to call.

Two people edit the same doc offline. Hello World. Goodbye. Both at position zero. They sync. Last write wins, and someone's work just vanishes. And a scheduler where two nodes both think they're the leader. The same job runs twice.

But here's the catch. Make everything strong, and it's correct, but needlessly slow. Make everything eventual, and your critical paths break. Like that checkout.

Five days. Consistency models. Sagas. Durable workflows. Merging conflicts. One leader. From make it fast, to make it correct. Then fast.

Full breakdown in the lecture.