Pessimistic locking and optimistic locking are two methods of concurrency control, the techniques a database uses to stop two processes changing the same record at once. In a payments ledger they protect an account balance from being read and updated by two transactions in parallel, which could otherwise let both spend the same money, a problem similar to double spending.
Pessimistic locking assumes clashes are likely: a transaction locks the row before reading it, and others must wait until it commits. This is simple and safe, but busy accounts, such as a platform's main settlement account, can become bottlenecks. Optimistic locking assumes clashes are rare: each record carries a version number, and an update succeeds only if the version has not changed since it was read; otherwise the transaction is retried. This scales better under low contention but causes many retries on "hot" accounts, so retried requests are made safe with idempotency. Many double-entry ledgers mix the two approaches.
Ref 1130000638