Loading
ACID Properties
Modern applications depend heavily on databases to store critical data such as money, orders, user accounts, and inventory. In such systems, even a small inconsistency can lead to serious problems. Imagine a banking system where money is deducted from one account but not credited to another, or an order system where payment succeeds but the order record is missing.

To prevent such situations, databases follow a set of rules known as ACID properties. These properties define how transactions should behave so that data remains safe, consistent, and trustworthy even in the presence of errors or system failures.


What Are ACID Properties?

ACID stands for:

  • Atomicity
  • Consistency
  • Isolation
  • Durability
Together, these four principles ensure that database transactions are processed reliably from start to finish.


Atomicity

All or Nothing
Atomicity ensures that a transaction is treated as a single indivisible unit. Either all operations succeed, or none of them do.
If any part of a transaction fails, the entire transaction is rolled back.


Example: Bank Transfer

UPDATE accounts SET balance = balance - 1000 WHERE acc_id = 1;
UPDATE accounts SET balance = balance + 1000 WHERE acc_id = 2;

If the second update fails:

  • Money must not be deducted from the first account
  • The database performs a ROLLBACK
This guarantees that partial changes never exist.


Key Points of Atomicity

  • No partial execution
  • Ensures logical completeness
  • Prevents half-done operations
  • Maintained using ROLLBACK


Consistency

Data Must Follow Rules
Consistency ensures that a transaction moves the database from one valid state to another valid state.
All constraints, rules, and validations must remain intact.

Exmaple: Constraint Violation

INSERT INTO employees (emp_id, salary)
VALUES (101, -5000);

If salary is defined with a CHECK constraint:

CHECK (salary > 0)

The transaction fails, preserving data integrity.


What Consistency Ensures

  • Primary keys remain unique
  • Foreign keys remain valid
  • Business rules are respected
  • No invalid data enters the database


Isolation

Transactions Should Not Interfere
Isolation ensures that multiple transactions running at the same time do not affect each other’s results.
Each transaction behaves as if it is the only one executing.


Example: Concurrent Transactions

  • Transaction A reads account balance
  • Transaction B updates the same balance

Without isolation:

  • Dirty reads or incorrect data may occur

With isolation:

  • Each transaction sees a consistent view of data


Isolation Problems Prevented

  • Dirty Reads
  • Non-repeatable Reads
  • Phantom Reads
(Handled using isolation levels like READ COMMITTED, SERIALIZABLE, etc.)


Durability

Once Committed, Always Saved
Durability guarantees that once a transaction is committed, its changes will persist permanently—even if the system crashes immediately after.


Example: System Crash After COMMIT

COMMIT;

Even if:

  • Power fails
  • Server crashes
  • Application stops
The committed data remains safe.


How Durability Is Achieved

  • Transaction logs
  • Write-ahead logging
  • Disk persistence
  • Backup and recovery mechanisms


ACID Properties at a Glance

PropertyPurposeExample
AtomicityAll or nothingROLLBACK
ConsistencyValid stateConstraints
IsolationNo interferenceLocks
DurabilityPermanent saveLogs


Real-World Importance of ACID

ACID properties are critical in:

  • Banking systems
  • Payment gateways
  • Stock trading platforms
  • Order management systems
  • Healthcare databases
Without ACID, such systems would be unreliable and unsafe.


Two Minute Drill

  • ACID ensures transaction reliability
  • Atomicity prevents partial updates
  • Consistency enforces rules
  • Isolation avoids interference
  • Durability preserves committed data
  • ACID is the backbone of safe databases