advancedConcurrency — Optimistic & Pessimistic Locking, MVCC
When would you choose pessimistic locking over optimistic locking?
When contention is high and a lost update or a retry storm under load would be genuinely unacceptable — for example, decrementing the last few units of inventory during a flash sale, where many concurrent buyers targeting the same rows would cause excessive optimistic-lock retries. Pessimistic locking makes conflicting transactions wait instead, guaranteeing no conflict happens at all.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response