Course contentsShow
← Data Engineering
Lesson 258 of 8254. Modern Data Warehousing and LakehousesFree lesson

Applying Multi-Version Concurrency Control for Concurrent Writes

Learners will learn how to resolve write conflicts using optimistic concurrency control to allow multiple users to update data concurrently without locking.

In this lesson, you will learn how to manage simultaneous updates in modern data systems using Multi-Version Concurrency Control (MVCC) to avoid the performance bottleneck of manual file locking.

The Problem: Write Conflicts

In traditional systems, when two users try to update the same dataset at the same time, the system often defaults to "pessimistic locking." This forces one user to wait until the other finishes, which is inefficient in high-throughput cloud environments. MVCC offers a better way: instead of locking the data, the system treats data as immutable and creates a new version for every change.

How MVCC Handles Concurrent Writes

With MVCC, the system uses Optimistic Concurrency Control (OCC). When a process wants to write, it reads the current metadata (like the latest version or snapshot ID). It then makes its changes and prepares to commit. During the commit phase, the system performs a "conflict check":

  1. Verify: Does the version I originally read match the current version?
  2. Commit: If no one else has committed an update since I started, I write my new version.
  3. Retry: If someone else changed the data, my commit fails, and I must re-read the latest version and try again.

Think of it like collaborating on a document: instead of preventing others from opening the file, everyone works on their own copy. When you save, the system checks if someone edited the file while you were working. If they did, you are asked to merge those changes before saving your own.

-- Conceptual flow of an OCC write operation:
-- 1. Read current version: v10
SELECT * FROM my_table VERSION AS OF v10;

-- 2. Perform updates and prepare new file (v11)
-- 3. Attempt commit:
-- IF (current_version == v10) THEN COMMIT (v11)
-- ELSE ROLLBACK AND RETRY

This approach is highly effective for data lakehouses because it relies on the immutability of underlying object storage. By keeping multiple versions available, we ensure that writers don't interfere with each other, keeping the system responsive even under heavy concurrent load.

Key Takeaway: MVCC enables concurrent writes by treating data as versioned snapshots, allowing multiple users to work simultaneously and using conflict checks to ensure only valid, non-conflicting updates are persisted.