Skip to main content
← Lab

Transaction isolation lab/ CONCURRENCY

Learn
中文 ↗

DATABASE CONCURRENCY / 01

Two orders. One stock count.

Predict the result, then trace an overwritten stock deduction.

THE CONCURRENT CHECKOUT
Product A · Initial stock 1010

Both orders read 10

Order one buys 1 unit; order two buys 2. Each reads stock, calculates locally, then writes its calculated constant back.

T1

Order one · 1 unit

Read 10Calculate 9
T2

Order two · 2 units

Read 10Calculate 8

This models an application reading, calculating, then writing a constant. It differs from an atomic database update such as UPDATE stock = stock - n.

← → chapters · Controls keep their usual keys01 / 06
Preparing the lab