Optimistic vs. Pessimistic locking in Rails

While performing concurrent operations, a database must ensure data integrity. ACID compliant relational database ensures this data integrity through its locking mechanism. ACID = Atomicity, Consistency, Isolation, Durability Locks can be at the database, table, page, or row level. Here is a beginner's guide to database locking in PostgreSQL. In this article, let's see how Rails provides a mechanism for optimistic locking on ActiveRecord models. However, before we proceed, let us first understand the basics of optimistic and pessimistic locking. What is optimistic locking? Let's take an example of two admin users, Mohan and Ritesh, managing the product inventory in their