Medium Database Systems Transactions & ACID
Compare optimistic and pessimistic locking strategies.
Answer
Pessimistic locking locks resources when accessed, preventing conflicts but reducing concurrency - SELECT FOR UPDATE. Good when conflicts are frequent. Optimistic locking assumes conflicts are rare, checks at commit time (using version/timestamp) - if data changed, reject and retry. Better for high-read systems with infrequent writes. ORM frameworks often support optimistic locking. Choice depends on conflict frequency and acceptable retry rate.
IIT Certified
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.
Relevant for Roles
Software Engineer Backend Developer Database Developer