Multiversion concurrency control (MVCC) provides a method for enabling simultaneous access to a database. Instead of overwriting data during updates or transactions, MVCC creates a new version or snapshot of the data. This allows only the initiating transaction to see the modified data until the changes are finalized. Meanwhile, other operations continue accessing the earlier snapshot. When older versions are no longer in use, they are automatically discarded.

By retaining multiple data versions, MVCC ensures non-blocking operations, even in scenarios with heavy queries, scripts, or transactions. This approach enhances isolation and functionality compared to traditional systems and offers significantly better concurrency than two-phase locking.


Key differences between MVCC and traditional locking

Rather than locking records during updates, MVCC generates a new version with an incremented identifier. Other operations can access the previous version without contention or deadlock risks. Once updates are finalized, future reads access the updated version, and the cycle repeats for subsequent modifications.


Drawbacks of MVCC

  1. Implementation complexity: Managing multiple versions of data requires intricate control methods.
  2. Data bloat: Maintaining multiple snapshots increases database size and can lead to inefficiencies.

Advantages of forkless background saving

One of the features enabled by MVCC is forkless background saving, which optimizes memory usage during save operations.

Traditional snapshotting using the fork() system call can cause write amplification, where even small changes result in duplication of entire memory pages. Additionally, sufficient free memory must be reserved to accommodate ongoing writes, and inadequate memory can lead to failures.

Forkless background saving minimizes these issues by avoiding such duplications, reducing the memory required for saving, and delivering consistent performance regardless of the size of the data being saved. This approach is particularly advantageous as database sizes and value complexities increase, making it faster and more memory-efficient.