Multi-version Concurrency Control

RedditHackerNewsX
SUMMARY

Multi-version Concurrency Control (MVCC) is a database concurrency control method that allows multiple versions of data to exist simultaneously, enabling readers to see a consistent snapshot without blocking writers. Each transaction works with a version of the database as it existed at the start of the transaction, while allowing other transactions to create new versions concurrently.

How MVCC works

MVCC maintains multiple versions of each data record, each tagged with transaction timestamps or version numbers. When a transaction modifies data:

  1. A new version is created rather than overwriting existing data
  2. The old version is retained for ongoing transactions that might need it
  3. Each transaction sees a consistent snapshot based on its start time

Next generation time-series database

QuestDB is an open-source time-series database optimized for market and heavy industry data. Built from scratch in Java and C++, it offers high-throughput ingestion and fast SQL queries with time-series extensions.

Benefits in time-series systems

In time-series databases, MVCC is particularly valuable because:

  1. Time-series data is often append-heavy with concurrent reads
  2. Historical queries need consistent point-in-time views
  3. Real-time analytics require isolation from ongoing writes

For example, a financial system can simultaneously:

  • Ingest live market data
  • Run historical analysis
  • Serve real-time dashboards

Each operation sees a consistent version of the data without blocking others.

Next generation time-series database

QuestDB is an open-source time-series database optimized for market and heavy industry data. Built from scratch in Java and C++, it offers high-throughput ingestion and fast SQL queries with time-series extensions.

Version cleanup and storage considerations

MVCC systems must manage version cleanup (vacuum) to prevent unbounded storage growth:

  1. Track the oldest active transaction
  2. Identify versions no longer visible to any transaction
  3. Remove obsolete versions while maintaining referential integrity

The cleanup process balances:

  • Storage efficiency
  • Query performance
  • Transaction isolation guarantees

Implementation approaches

Modern databases implement MVCC through various strategies:

  1. Append-only storage: New versions are appended to tables or write-ahead logs
  2. Time-travel storage: Versions are organized by timestamp for efficient historical access
  3. Delta storage: Only changes are stored between versions

These approaches often combine with other features like snapshot isolation for additional consistency guarantees.

Subscribe to our newsletters for the latest. Secure and never shared or sold.