ACID Properties Deep Dive (Atomicity, Consistency, Isolation, Durability)
Explain ACID guarantees and what each letter means under failure.
In plain words
A transaction is all-or-nothing, keeps the rules, isn't disturbed by others, and is never forgotten once it's saved.
Think of it like…
A bank transfer at a counter: the cashier either completes both the withdrawal and the deposit or neither (atomicity), never lets an account go below its limit (consistency), serves one customer's transfer without the next customer seeing it half-done (isolation), and writes it in the ledger before handing you the receipt (durability).
Where you’ve seen it
Moving ₹500 between accounts: BEGIN; UPDATE accounts SET balance = balance - 500 WHERE id = 1; UPDATE accounts SET balance = balance + 500 WHERE id = 2; COMMIT;. If the server crashes after the first UPDATE, atomicity means neither change is kept.
Words you’ll hear
- Transaction
- A group of statements treated as one unit: BEGIN … COMMIT or ROLLBACK.
- Write-ahead log (WAL)
- A log written and flushed before data pages; it's how databases provide atomicity and durability after a crash.
- Constraint
- A rule the database enforces (NOT NULL, UNIQUE, FOREIGN KEY, CHECK).
- Isolation level
- How strictly concurrent transactions are kept apart.
Visual diagram
Theory & example queries
What each letter really guarantees
Atomicity: if anything fails before COMMIT (an error, a crash, a ROLLBACK), every change in the transaction is undone. Consistency: the database enforces its constraints, so a transaction that would violate a NOT NULL, UNIQUE, FOREIGN KEY or CHECK rule fails as a whole. Business rules the database doesn't know about are still your code's job.
Isolation: concurrent transactions behave as if separated to a degree set by the isolation level; at the default Read Committed, some anomalies are still possible. Durability: once COMMIT returns, the change is in the write-ahead log on disk and will be recovered after a crash or power loss.
| id | owner | balance |
|---|---|---|
| 1 | Maya | 1000 |
| 2 | Ravi | 500 |
ALTER TABLE accountsADD CONSTRAINT balance_non_negative CHECK (balance >= 0);PostgreSQL is the lesson baseline unless noted otherwise.
Identify the table or database object the statement will modify.
Expected output
Note: Representative PostgreSQL status; the command fails if any existing balance violates the new constraint.
A transfer that would overdraw the account now fails and is rolled back.
Key takeaway: Atomicity and durability handle failures; consistency and isolation handle rules and concurrency.
How databases deliver ACID, and where it bends
Most relational databases use a write-ahead log: changes are recorded in the log and flushed to disk before COMMIT returns, so after a crash the database replays committed work and discards uncommitted work. Isolation is provided by locks, MVCC snapshots, or both.
Some settings trade guarantees for speed. PostgreSQL's synchronous_commit = off can lose the last few hundred milliseconds of commits on a crash, and asynchronous replicas can be behind when a failover happens. Many distributed and NoSQL systems relax isolation or atomicity across partitions; know what yours promises.
| id | owner | balance |
|---|---|---|
| 1 | Maya | 1000 |
| 2 | Ravi | 500 |
BEGIN;UPDATE accountsSET balance = balance - 500WHERE id = 1;ROLLBACK;PostgreSQL is the lesson baseline unless noted otherwise.
Open a transaction so changes can be checked and committed or rolled back together.
Expected output
Note: Assumes account 1 exists; the displayed update is discarded by the rollback.
The debit is undone, as if it never happened. The same happens automatically if the session crashes before COMMIT.
Key takeaway: ACID holds only as strongly as your durability settings and isolation level.
How it works, step by step
Follow one practical SQL workflow from start to finish. Select any step or play through the flow.
Group related changes
Put every statement that must succeed or fail together between BEGIN and COMMIT.
BEGIN;… two UPDATEs …COMMIT;When to use it & trade-offs
What it is
ACID is the set of guarantees a database gives for transactions. Atomicity: all of a transaction's changes happen, or none do. Consistency: every transaction leaves the data valid under its constraints. Isolation: concurrent transactions don't see each other's half-finished work. Durability: once committed, changes survive a crash.
Why it matters: These guarantees are why you can trust a database with money, orders and inventory. Interviewers ask about ACID to see whether you understand what happens on failure, such as a crash halfway through a transfer, and what each property actually protects you from.
When to reach for it
- Explaining why a transfer needs a transaction
- Deciding which rules to enforce as database constraints
- Reasoning about what happens if the server crashes mid-operation
When to avoid or be careful
- Running related changes as separate auto-committed statements
- Confusing ACID consistency with CAP consistency (replicas agreeing)
- Turning off synchronous commit for data you can't afford to lose
The four properties side by side
Strengths: No half-finished state after an error or crash.
Watch out: Long transactions hold locks and resources until they finish.
Strengths: Invalid data is rejected at write time.
Watch out: Only covers rules declared as constraints; business logic still lives in code.
Strengths: No interference between transactions; committed data isn't lost.
Watch out: Stricter isolation costs waiting or retries; full durability costs a disk flush per commit.
Interview signals & numbers to know
When this topic comes up
- “Explain ACID”
- “What happens if the server crashes in the middle of a transfer?”
- Transactions and rollback
- “Is MongoDB / your NoSQL store ACID?”
- Write-ahead log
Benchmarks & rules of thumb
- 4
- properties: A, C, I, D
- 0
- changes kept from a transaction that didn't commit
- 1 flush
- of the WAL per commit for full durability
Common mistakes & follow-ups
Common interview mistakes
- Saying consistency means "replicas agree"; that's the C in CAP, not in ACID.
- Assuming isolation means transactions never interfere, at any isolation level.
- Doing a transfer as two separate statements without a transaction and relying on nothing failing in between.
Likely interviewer follow-ups
- How does a database guarantee durability after a power failure?
- What's the difference between consistency in ACID and in the CAP theorem?
- Which ACID property is weakened by Read Committed isolation, and how?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply ACID Properties Deep Dive (Atomicity, Consistency, Isolation, Durability) with hands-on SQL practice and interview Q&A.