Lesson 3 of 14
8. SQL vs NoSQL

8.2 What does ACID mean?

3 min read+10 XP

In the office: The accountant has four rules. A sale is recorded completely or not at all. The books always balance. Two clerks writing at once don't scribble over each other. And once written in ink, it survives even if the lights go out.

In the system: ACID is the set of promises a database makes about transactions: groups of changes treated as one unit.

LetterMeansBookstore example
AtomicityAll the changes in a transaction happen, or none doSave the order and reduce the stock, or neither
ConsistencyEvery transaction leaves the data obeying its rulesStock can never go below zero; every order points at a real user
IsolationTransactions running at the same time don't see each other's half-done workTwo people buying the last copy don't both succeed (Chapter 17)
DurabilityOnce committed, the change survives a crashThe confirmed order is still there after a power cut

In code, a transaction looks like this:

sql

Note the C in ACID isn't the same "consistency" as in CAP (Chapter 16). Here it means "the database's rules still hold".

Memory code: "All or nothing, rules always hold, no peeking, written in ink." Atomic, Consistent, Isolated, Durable.