ACID is an acronym that stands for Atomicity, Consistency, Isolation, and Durability. These four properties are fundamental to ensuring the reliability and consistency of database transactions. A transaction is a sequence of operations that are treated as a single unit of work.

Atomicity

  • A transaction is treated as an indivisible unit. Either all operations within the transaction are completed successfully, or none of them are.

  • If you transfer money from one account to another, both the debit from the source account and the credit to the destination account must be completed successfully. If one fails, the entire transaction is rolled back, leaving the database in its original state.

Consistency

  • The database must be in consistent state before and after the transactions. The transaction should not change the consistent state of the database. It must adhere to all defined rules and constraints.

  • If a bank account has a balance of $100, a transaction that attempts to withdraw $150 should be rejected, as it would result in a negative balance, violating the bank’s rules.

Isolation

  • Concurrent transactions should not interfere with each other. Each transaction should appear to be executed in isolation, as if it were the only transaction running in the system.

  • If two customers are simultaneously trying to buy the last ticket for a concert, only one transaction should be successful. The other transaction should either wait or be rejected, ensuring that the ticket is not sold to multiple customers.

Durability

  • Once a transaction is committed, its effects must be permanently recorded in the database. Even if the system crashes or experiences a power outage, the committed changes should be preserved.

  • If you successfully transfer money from your account to another, the transaction should be recorded permanently, even if the system crashes before you can see the updated balance.

The ACID properties are essential for maintaining the integrity and reliability of database systems. They ensure that transactions are executed correctly and that the database remains in a consistent state, even in the face of concurrent operations and system failures.