Skip to content
About
Main content
Concurrency & Consistency

Transactions & Concurrency Control

What happens when many users change the same data at the same time, and how do we keep the result correct?

Who this mechanism is for: a developer who writes code, calls APIs and knows basic SQL, but has never studied how a database lets many users work on the same data at once. You do not need any database-internals knowledge. Every technical term is explained the first time it appears, and again in the glossary at the end.

The story we will follow

Tomas Berg is a backend engineer at Kestrel Tickets, a small company that sells concert and sports tickets online. Each customer also has a prepaid wallet: customers add money to it and pay for tickets from it. Tomas owns the order service. It reserves seats, charges wallets and records orders in one SQL database that we will call orders-db. His colleague Lena Okafor is the database engineer and the on-call lead. She is calm, she measures everything, and her favourite question is "what is the rate?"

Normally Kestrel handles about 800 orders per second. Next month the company sells tickets for the Hollowmoon Tour. The sale will reach 8,000 orders per second for a few minutes, and most buyers will fight for the same 200 "floor" seats out of 50,000. Across this mechanism Tomas will meet five problems, one at the start of each article. Each problem looks like a bug. Each one is actually a consequence of arithmetic or of a design choice that every database makes. At the end of each article we go back and solve his problem with the mechanisms of that article.

This is the main idea of this mechanism:

How this mechanism is organized

After that: a summary, hands-on labs, interview questions and a glossary.

One request: do the small calculations here with a pencil. The central results (for example "ten times the is a hundred times the conflict") are not opinions. They are arithmetic, and the arithmetic predicts what your system will do.

What do I do, and what does each option cost?

Can I see it myself?

Can I reason about it under questioning?

Trade-offs

The tensions this mechanism takes a position on. Each recurs across mechanisms.

Recurring principles

Ideas this mechanism meets that keep coming back, mechanism after mechanism.

Show all 14 principles