ACID Properties
What atomicity, consistency, isolation and durability each promise, which part of the database delivers each one, and where the promises stop.
Overview
Why transactions exist
A transaction groups several reads and writes into one unit. The database then either applies all of them or none of them, and keeps other clients from seeing the work half done. Without transactions, every application would have to handle crashes, half-finished writes and concurrent clients on its own.
ACID names four promises a transaction makes. The acronym comes from Theo Härder and Andreas Reuter's 1983 paper on database recovery. Each letter solves a different problem, and a different part of the system delivers it.
- Atomicity (all or nothing): it handles a crash or error halfway through. The database aborts and rolls back the unfinished transaction on any failure.
- Consistency (the rules stay true): it handles data that breaks a business rule. Constraints in the database and checks in the application code deliver it, and it is the only letter the application owns.
- Isolation (no interference): it handles two clients working on the same data. Concurrency control delivers it, through locks or MVCC (multi-version concurrency control) at a chosen isolation level.
- Durability (commits survive): it handles power loss right after a commit. A write-ahead log flushed to disk delivers it, and replicas add to it.
The rest of this chapter takes the letters one at a time, starting with the one that deals with failure.
Key concepts
- Transaction
- Atomicity
- Consistency
- Isolation
- Durability
- Write-ahead log (WAL)
- fsync
- Synchronous replication
Interview questions
- What does durability mean in practice, and how is it implemented?
- How is atomicity different from isolation?
- Is consistency guaranteed by the database?
- A vendor says their database is ACID compliant. What do you ask?
- How does a database throw away an unfinished transaction after a crash?
Sign up free to read the full topic
More DDIA topics
- B-Trees and Write-Ahead Logs
- Beyond MapReduce: Dataflow Engines
- Change Data Capture (CDC)
- Clocks and Time in Distributed Systems
- Column-Oriented Storage and Compression
- Consensus Algorithms: Paxos and Raft
- Consistency Guarantees: Eventual, Causal and Linearizable
- Declarative vs Imperative Query Languages
- Encoding Formats: JSON, Protobuf, Avro, Thrift
- End-to-End Correctness and the Exactly-Once Myth
- Event Streams and Message Brokers
- Fan-Out and the Twitter Timeline Problem
Start free on Cariara · Coding problems · System design studio