---
title: "Concurrency Control: Locks and Snapshots"
description: "Two-phase locking makes transactions wait for each other and can deadlock. Multi-version concurrency control gives each transaction a consistent snapshot instead, so readers never block writers, at th"
canonical: https://lightmysky.com/learn/computing/concurrency-control-locks-and-snapshots-mt_gOd17LRKel
source: https://lightmysky.com/learn/computing/concurrency-control-locks-and-snapshots-mt_gOd17LRKel.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Concurrency Control: Locks and Snapshots

Two-phase locking makes transactions wait for each other and can deadlock. Multi-version concurrency control gives each transaction a consistent snapshot instead, so readers never block writers, at the price of keeping old versions around.

Subject: Computing · Area: Data & Databases · Ages 20 to 21
Page: https://lightmysky.com/learn/computing/concurrency-control-locks-and-snapshots-mt_gOd17LRKel

## Ready when they can

- Explain what the two phases of two-phase locking are and why the order matters
- Say what a transaction sees under snapshot isolation and when that view was taken
- Describe a write conflict that a snapshot system has to detect at commit

## Lesson: Waiting locks or private snapshots

Isolation says each transaction must behave as if it has the database all to itself, even while transactions overlap. Two strategies keep that promise. Locking makes transactions wait for each other. Snapshots give each transaction a consistent picture instead, so readers never block writers, at the price of keeping old versions around.

**Example.** With two-phase locking, a transaction first grows: it collects every lock it needs and releases none. Then it shrinks: it releases locks and takes no new ones. The order matters. Releasing early and taking another lock later would let a second transaction slip a change in between, and the first would lose its clean private view.

With snapshots, each transaction reads from a picture of the database taken when it started, no matter what others commit meanwhile. A long report can run to the end without ever blocking a writer. The database pays by keeping old row versions around so every open picture stays readable.

**Tip.** Waiting has one danger: deadlock. Two transactions each hold a lock the other wants, and then neither moves, so the system must spot the standstill and cancel one side. Snapshots have their own clash: two transactions changing the same row from the same picture must be caught at commit, and only one wins.

**Recap.** Locks make transactions wait in two phases, snapshots let them proceed from private pictures, and each path has its own clash.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Deadlock and the Four Conditions](https://lightmysky.com/learn/computing/deadlock-and-the-four-conditions-mt_CsMOA4sBb1)
- [Isolation Levels and the Anomalies They Allow](https://lightmysky.com/learn/computing/isolation-levels-and-the-anomalies-they-allow-mt_utxPNgxveB)

## Opens up

- [Crash Recovery and Write-Ahead Logging](https://lightmysky.com/learn/computing/crash-recovery-and-write-ahead-logging-mt_JFPafSWOWF)
