ACID Properties in Databases
Definition
ACID is an acronym for Atomicity, Consistency, Isolation, and Durability — the four properties that guarantee database transactions are processed reliably even in the presence of errors, power failures, and concurrent access.
Introduction to ACID Properties in Databases
ACID properties are the bedrock guarantee of relational databases. They exist because real-world operations — bank transfers, order processing, inventory management — require absolute confidence that partial failures, system crashes, or concurrent users will not leave data in an incorrect state. Every major RDBMS (PostgreSQL, MySQL, SQL Server, Oracle) implements ACID guarantees.
Key Takeaways
- Atomicity: implemented via rollback logs — on failure, the database replays the log to undo partial changes
- Consistency: implemented via constraints (CHECK, NOT NULL, FOREIGN KEY), triggers, and cascades
- Isolation: implemented via locking (pessimistic) or MVCC — Multi-Version Concurrency Control (optimistic)
- Durability: implemented via Write-Ahead Logging (WAL) — changes are logged to disk before the commit succeeds
- MVCC allows readers and writers to not block each other — PostgreSQL and InnoDB use MVCC
- BASE (Basically Available, Soft state, Eventually consistent) is the NoSQL alternative to ACID
Real-World Examples & SQL Schema
ACID in Action — E-commerce Order
BEGIN; -- Atomicity: all or nothing INSERT INTO orders (customer_id, total) VALUES (42, 299.99); -- Consistency: stock cannot go negative (CHECK constraint) UPDATE products SET stock = stock - 1 WHERE id = 101 AND stock > 0; -- Isolation: other sessions don't see this until COMMIT -- (MVCC: readers see the old stock value) CHARGE_PAYMENT(42, 299.99); -- application call COMMIT; -- Durability: WAL entry flushed to disk — data survives crash
A complete order transaction showing all four ACID properties in action.
Run code in PlaygroundPrimary Use Cases
Financial systems: every transaction must balance (debit = credit)
Healthcare: patient records must be consistent and never partially written
E-commerce: orders, inventory, and payments must be atomically coordinated
Booking systems: seat/room availability must not be double-booked