Database: Optimistic vs. Pessimistic Locking
Detail the tradeoffs between optimistic concurrency control (OCC) and pessimistic locking in high-throughput databases.
Technical Reference & Key Concepts
The Challenge: Concurrency Control
Your application experiences race conditions during high-concurrency balance updates. You must choose between Optimistic (OCC) and Pessimistic locking.
Core questions to address:
- In what scenario is Optimistic Locking (OCC) preferred over Pessimistic Locking?
- What is the operational cost of transaction retries under high contention in OCC?
- How do you implement Pessimistic locking in SQL (e.g., using Postgres)?