In computer science ACID properties stands for below :
- A : Atomicity
- C : Consistency
- I : Isolation
- D : Durability
Transactions are mostly composed of multiple statements. Atomicity guarantees that each transaction is treated as single unit, which either succeeds completely or fails completely.
Example: Suppose a person is trying to do a transaction in which person is trying to transfer money from A's account to B's account. So in this case amount will be debited from A and same amount will be credited to B. But if this transaction fails at any point, then the balances of A and B will be remain unchanged.
- A-------------------------------->B (10$)
- A-10 ----------------------------> B
- Transactions fails
- B wasn't updated
- Rollback
- A remain unchanged (No deduction)
Consistency:
Consistency insures that transaction can bring database from one valid state to another. This prevents data corruption by illegal transaction. Means transaction should follow all rules to bring database from one valid state to other. Here rules could be any check constraints, triggers, foreign keys etc.
Example:
- Transferring 10$ from A to B
- So A-10 -------------------> B+10
- It should be not be doing A-5 and adding B+10
Isolation:
Isolation means all transactions running in parallel should be isolated from each other.Isolation is the main goal of concurrency control.
Consider two transactions: T1 transfers 10 from A to B. T2 transfers 20 from B to A.
Combined, there are four actions:
T1 subtracts 10 from A.
T1 adds 10 to B.
T2 subtracts 20 from B.
- T2 adds 20 to A.
If these operations are performed in order, isolation is maintained, although T2 must wait. Consider what happens if T1 fails halfway through. The database eliminates T1's effects, and T2 sees only valid data.
By interleaving the transactions, the actual order of actions might be:
T1 subtracts 10 from A.
T2 subtracts 20 from B.
T2 adds 20 to A.
- T1 adds 10 to B.
- Service outages
- Crashes
- Other cases of failure
- Transfer 10$ from A to B.
- Valid state: A-10 to B+10
- Transaction committed successfully.
- Power failure occurred
- Checked database after system is up
- All changes done by transaction are there.