Two phones add to one cart at once. Which item survives?
transcript
Two phones add to the same cart. At the same moment. One item silently disappears. No error. Nobody notices.
Phone 1 adds item A to the cart. Phone 2 adds item B. Neither saw the other's write. The simple rule: last write wins. Highest timestamp keeps the key. So item A is just gone. Thrown away without a word.
It gets worse. Those timestamps come from different machines. With clock skew, the older write can win.
The fix is vector clocks. Each version carries a counter per writer node. Compare them. Neither version follows the other. They're concurrent. So the store returns both. The client merges them: the union of two carts. It writes the merge back. Item A and item B both stay.
So is last write wins wrong? No. For a profile photo URL, it's fine. For a cart, losing an item is worse than showing a merge.
Last write wins hides the conflict. Vector clocks show it. Two writes at once? Keep both, and let the client merge.
Full breakdown in the lecture.