Pessimistic vs Optimistic locking
Sandeep Singh
@Walmart Labs| Ex-Visa |S/W, Data Enginner | NLP | DL| ML| Time Series Forcasting| Spark,Kafka | Microservices/Event driven | DevOps(Docker,K8s)
Pessimistic locking: When we lock the record exclusively for our exclusive use until we have finished it. The disadvantage is that a resource is locked from the time it is first accessed in a transaction until the transaction is finished
We can go for this locking mechanism in case of more conflicts or transactional systems. eg: database locking.
Optimistic locking: With this locking, a resource is not actually locked when it is first accessed by a transaction. Here we read a record, take note of a version number and check that the version hasn't changed before we write the record back.
We can go for this locking mechanism in case of less conflict. eg: Wikipedia update.
Correct me if anything is wrong.