---
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/en/learn/computing/concurrency-control-locks-and-snapshots
source: https://lightmysky.com/learn/computing/concurrency-control-locks-and-snapshots.md
license: https://lightmysky.com/en/license
retrieved: 2026-12-04
---

> **Using this content.** You may index it, quote short parts, and use it to answer a person's question, if you name LightMySky and link to the page. You may train models on it.
> Please do not republish, resell or serve our lessons and questions as another product.
> [Topic data credits and licenses](https://github.com/withmarbleapp/os-taxonomy#attribution) (ODbL 1.0 for the database and CC BY-SA 4.0 for the topic text).
> Full license: https://lightmysky.com/en/license

> **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/en/learn/computing/concurrency-control-locks-and-snapshots

## 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.

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. Plain snapshots still allow write skew: changes to different rows that together break a rule both read. Serializable catches it.

**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

- [Isolation Levels and the Anomalies They Allow](https://lightmysky.com/en/learn/computing/isolation-levels-and-the-anomalies-they-allow)

## Optional connections

- [Deadlock and the Four Conditions](https://lightmysky.com/en/learn/computing/deadlock-and-the-four-conditions)

## Opens up

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