Skip to content
About
Main content
Concurrency & Consistency

Consistency & Isolation Models

When many users, many objects and many copies exist at once, which histories does the system promise never to show, and who writes the code for the histories it does show?

Who this mechanism is for: a developer who writes backend code and knows basic SQL, but has never studied what "", "strong consistency" or "" really promise. You do not need to know how a database is built inside. Every technical term is explained the first time it appears, and again in the glossary at the end. This mechanism explains ideas, not products: when it mentions PostgreSQL, MySQL, Oracle or Cassandra, it is to show that the same idea has different names in different places.

The story we will follow

Anika is a backend engineer at Pebble, a small company with a mobile wallet app. Users hold balances, send money to friends, pay merchants, join promotions and attach short notes to payments. Anika owns the ledger service, the code that records every movement of money. Her colleague Tomás is the platform engineer. He owns the database servers, the read copies (), the caches and, later, a second region.

Pebble's ledger is a PostgreSQL-style database in Frankfurt: one (the copy that accepts writes) and read replicas. Peak load is about 40,000 transfers per minute. Copies normally lag the primary by about 20 ms, and by up to 2 s under load. Later Pebble opens a second region in Singapore, 80 ms of network delay away. All numbers in the story are illustrations.

Over the six parts of this mechanism Anika meets six problems, one at the start of each article. Each problem looks like a bug in the code. None of them is. Each is a consequence of what a consistency or isolation level does not promise. At the end of each article we go back to Anika and solve her problem with the part's ideas.

The main idea of this whole mechanism:

How this mechanism is organized

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

A request: do not skip the small examples with two or three transactions. Almost every claim here can be checked by writing three short transactions in a database console. The labs do exactly that.

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 12 principles