ACID Properties in DBMS Explained with Examples
Atomicity, consistency, isolation and durability, each shown with a bank transfer and the undo, constraints, locks or log that keeps it.
In this chapter
ACID: the four promises behind every transaction
ACID: common questions
What are the ACID properties?
Atomicity: all or nothing. Consistency: rules and constraints hold. Isolation: concurrent transactions do not see each other half-done. Durability: a committed change survives a crash.
Which part of the database provides durability?
The write-ahead (redo) log. A commit returns once its log record is flushed to disk.
More on Transactions: ACID
Keep learning
Overview
chapters · transactions, isolation and locks ACID: the four promises behind every transaction Moving $100 takes two writes, and a crash, a nosy reader or a power cut in between can make money vanish.
1. What a transaction is
A group of statements treated as one unit: all happen, or none do. SELECT balance id 1 has ≥ 100? UPDATE id 1 UPDATE id 2 A transfer is a check plus two updates. Changes become permanent and visible. Changes are thrown away. Crash / dropped link Treated as a rollback. Always in one No BEGIN? Autocommit wraps each statement. Read-only too Reports see one moment, numbers agree. Keep them short Long ones hold locks and undo slowly. 1,000 updates: write each as it goes, or hold them all until COMMIT? Apply each change as it runs COMMIT: fast, just mark committed.ROLLBACK: slow, undo every change. Hold changes aside until the end COMMIT: slow, apply all at once.ROLLBACK: cheap, discard pending. Most engines apply as they go and bet on COMMIT. The rollback bill differs: MySQL / InnoDB Applies changes as it goes Where old values live old row versions stay copied to undo log Rollback work mark new versions dead, clean later copy old values back
2. Atomicity: all of it, or none of it
Crash the transfer at different steps, with and without a transaction, and compare totals. UPDATE id 1 −100 undo info saved first 💥 crash no ROLLBACK sent restart: no commit record undo it Without undo at restart, $100 would be gone. total before without undo with atomicity Many things abort it Broken rule, duplicate key, syntax error, deadlock. One failure undoes all The log decides No commit record → undone, whatever hit disk. Database only Cannot recall a sent email or HTTP call. Without BEGIN, each statement commits alone → next chapter.
3. Isolation: transactions running at once don't see each other's half-done work
T1 has not committed, so T2 must not see its change: T1 might still roll back. not committed 100 (50 pending) SELECT balance must see 100 50 never existed Strict isolation Safe, but more waiting and slower. Looser levels Faster, but allow known anomalies. SQL offers four isolation levels. Most bad data comes from broken A or weak I. what can go wrong which each stops
4. Consistency: in the data, and in what you read
In the data (the C in ACID) Data obeys the rules its designer set. In reads The next read sees the latest commit.
Consistency in the data
but only 2 picture_likes rows. like → picture 4 but picture 4 was deleted. PRIMARY KEY NOT NULL FOREIGN KEY Declared rules: a violating statement is refused before commit. You define, it enforces No foreign key? Order for missing customer accepted. Some rules can’t be declared Like counts, “one doctor on call”: need A, I or locks.
Consistency in reads
replica / cache replica holds primary has "B" SELECT name stale: "A" catch up now "B" Eventual consistency: relational databases with replicas have it too. Sometimes fine 7,000 likes instead of 7,011 for seconds. Sometimes not Lagging balance → double withdrawal. Read primary or sync-replicate. Corrupt stays corrupt 3 of 7 tables updated never heals by waiting.
5. Durability: committed means it survives a crash
Rewrite every page at commit Tables + indexes flushed each time: slow. Append to write-ahead log (WAL) into OS page cache OS says OK still only in memory! wait for real disk reply COMMIT now safe fsync is slow, so engines group several commits into one flush. Log replay redoes committed work. Undo info rolls back the rest. MySQL / InnoDB Redis AOF fsync every write Losing 1 s is fine Logs, sensor readings. Losing 1 s is not → write-ahead log · buffer and log
6. Diagnose a failure by its letter
Pick the letter whose promise was broken. ⚙ In real engines
Remember
One outcome Undo + commit record Unfinished work undone, even after crash. Speed vs safety dial Built from locks and snapshots. You declare, it enforces Stale replica reads are a different problem. fsync log before ack → next: autocommit, errors and savepoints
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.