OLTP (Online Transaction Processing) 00:00:01 Two pastries left and three hungry buyers At the counter the bakery must reserve stock, create an order and record the price together. Online transaction processing serves many short interactions like this while keeping the shop's business rules intact. Alice asks for two items. Under the isolation level in this example, other shoppers cannot read her uncommitted changes. One statement checks that at least 2 are left and takes them. The row is now locked. One line for the product, with the price of today. Had the stock been 1, the update would change no row. A rollback leaves every table as it was. The checkout result depends on the condition applied by the database. A value read earlier on a product page is an invitation to try, never a promise that two pastries remain. 00:00:49 Watch the last ticket twice Put two buyers in front of the same last ticket. A polite availability check followed later by a separate write leaves an interval where each buyer believes they won. Both programs read the stock and see 1. Both write 0 and both hand out a ticket. One row changed: sold. The lock is released. The condition is checked again on the new value. Zero rows changed: sold out. Let the conditional update and its affected-row count determine the answer. One transaction gets the ticket. The other receives a normal sold-out result that the application must handle. 00:01:26 Two transfers meet head-on A transfer touches two accounts. When two clerks acquire them in opposite orders, each can hold what the other needs. The waiting arrows in the animation now form a cycle. T1 moves from account 1 to 2. T2 moves from 2 to 1. T1 holds 1 and waits for 2. T2 holds 2 and waits for 1. The database stops one of them. T1 gets 1 and 2. T2 waits for 1 and holds nothing, so T1 can finish. T1 checks the balance, moves the money and commits. Then T2 does the same. Acquire both account locks in the same stable order, even when the money flows the other way. Keep transactions short and make the entire operation safe to retry after a deadlock victim is chosen. 00:02:15 Pull the plug between the two sales The bakery loses power after a commit and during a later update. The recovery process has to distinguish work the shop promised from work that never made it over the commit boundary. T41 committed. T42 changed the seats to 48 and then the power failed. Only T41 has a commit record. T42 never committed, so its change does not count. Nobody was told that it succeeded. Every answered commit is there and nothing half done remains. With durable commits configured, the log gives that boundary meaning. If the network drops the reply, the buyer may still be uncertain and should look up the order by its stable request identifier. 00:02:58 The card reader is much slower than the till Suppose checkout waits eight hundred milliseconds on a payment provider while holding the most popular stock row. A single slow external call turns a three-millisecond local update into a line around the corner. Lock the stock, call the provider, commit. At about eight hundred and three milliseconds per holder this one row can pass only about one point two checkouts per second. Reserve and commit. Call without a lock. Confirm in a second transaction. At three milliseconds the idealized row limit rises to about three hundred thirty-three per second. Other limits still apply. Reserve briefly and commit. Call the provider with an idempotency key, then confirm or release the reservation durably. Measure transaction time, lock waits and the customer's complete wait separately.