MVCC
MVCC (multi-version concurrency control) is a concurrency control mechanism used to provide consistency and isolation attributes (as defined in ACID) for shared data.
The aim of this blog is to give a very high-level understanding of MVCC, without going too much into any specific implementation details.
Lock based concurrency control
When you have multiple concurrent processes (or transactions) operating on a set of shared data, one way to provide consistency & isolation is by using “locks”.
But locks are expensive because when a process locks the data set for reading/writing, all other processes wanting to get access to the same data set will be blocked until the lock is released, which reduces the throughput of your system.
In the lock-based approach, a concurrent process takes the below steps to safely mutate the shared data.
- obtain the locks to the shared data
- perform some computations
- update the data elements
- release the locks
As you can see, when the process A
acquires all the locks and starts performing the computations, process B
has to wait till the process A
releases the lock, which is a problem.