Atomicity Consistency Isolation Durability (ACID)
ACID refers to a database system’s four transaction properties: atomicity, consistency, isolation and durability.
Transactions: A transaction is a single logical unit of work which accesses and possibly modifies the contents of a database. Transactions access data using read and write operations.
In order to maintain consistency in a database, before and after the transaction, certain properties are followed. These are called ACID properties. It is a sequence of operations that satisfies these properties.
Let's go ACID properties in detail:
Atomicity: Nothing or All
Atomicity is a property that ensures that a database follows the all or nothing rule. In other words, the database considers all transaction operations as one whole unit or atom. There is no midway i.e. transactions do not occur partially.
It involves the following two operations.
Abort: If a transaction aborts, changes made to database are not visible.
Commit: If a transaction commits, changes made are visible.
Thus, when a database processes a transaction, it is either fully completed or not executed at all. If a single portion of the transaction fails, the whole transaction will fail.
For example, user X wants to withdraw $50 from his account and then transfer it to the account of user Y. Each transaction (withdrawing $50 from account X and transferring $50 to account Y) is counted as separate. If the first transaction (withdrawing $50) fails because (say) the server crashes during the transaction, user X cannot transfer the money to user Y.
Consider the following transaction T consisting of T1 and T2: Transfer of 50 from account X to account Y.
Initial Balance: X=100 , Y=200
Consistency:
Isolation:
Durability
Durability is a property that enforces completed transactions, guaranteeing that once each one of them has been committed, it will remain in the system even in case of subsequent failures.
If a transaction is successful, all changes generated by it are stored permanently.
Let's say in above example, user Y may withdraw $100 only after user X’s transaction is completed and is updated in the database. If the system fails before X’s transaction is logged in the database, X cannot withdraw any money, and Z’s account returns to its previous consistent state.
So, once the transaction has completed execution, the updates and modifications to the database are stored in and written to disk and they persist even if a system failure occurs.