DEV Community

Pranav Bakare
Pranav Bakare

Posted on

ACID Properties in Database

Image description

The ACID properties in databases ensure reliable processing of transactions. ACID stands for:

  1. Atomicity: A transaction is all or nothing. It either fully completes or fully fails.

    • Example: In a banking system, transferring $100 from Account A to Account B involves two operations: subtracting $100 from A and adding $100 to B. If one operation succeeds but the other fails, atomicity ensures both actions are undone (rolled back) to maintain consistency.
  2. Consistency: A transaction must take the database from one valid state to another, preserving data integrity.

    • Example: If Account A has $500, and a transaction transfers $600 from it, consistency ensures this transaction would be invalid and rolled back.
  3. Isolation: Transactions should not interfere with each other. Intermediate states of a transaction should not be visible to other transactions.

    • Example: If one transaction is transferring money from Account A to Account B, another transaction querying Account A should see the balance before or after the transfer, but not during it.
  4. Durability: Once a transaction is committed, the changes are permanent, even in case of a system failure.

    • Example: After transferring money from Account A to Account B, if the system crashes immediately after, the changes will still reflect when the system is back online.

Example Scenario:
A system processing a financial transaction:

  1. Atomicity: If a bank transfer fails halfway, the entire transaction is rolled back.
  2. Consistency: The system ensures no transfer exceeds available funds.
  3. Isolation: Another query cannot access the account balance while the transfer is in progress.
  4. Durability: The transfer is permanently recorded after the transaction is committed, even if the server crashes.

These properties help maintain integrity and consistency in database systems.

Top comments (0)