Showing posts with label transaction. Show all posts
Showing posts with label transaction. Show all posts

What is ACID property in transactions.

 



In computer science ACID properties stands for below :

  1. A : Atomicity
  2. C : Consistency
  3. I : Isolation
  4. D : Durability

Atomicity:

Transactions are mostly composed of multiple statements. Atomicity guarantees that each transaction is treated as single unit, which either succeeds completely or fails completely.
Atomic system must guarantee the atomicity in each and every situation, including power failures, errors and crashes.


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.

  1. A-------------------------------->B (10$)
  2. A-10 ----------------------------> B
  3. Transactions fails 
  4. B wasn't updated
  5. Rollback
  6. 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:

  1. Transferring 10$ from A to B
  2. So A-10 -------------------> B+10
  3. 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:

    1. T1 subtracts 10 from A.

    2. T1 adds 10 to B.

    3. T2 subtracts 20 from B.

    4. 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:

    1. T1 subtracts 10 from A.

    2. T2 subtracts 20 from B.

    3. T2 adds 20 to A.

    4. T1 adds 10 to B.


Durability:

Durability ensures that changes made to the database (transactions) that are successfully committed will survive permanently, even in the case of system failures. This ensures that the data within the database will not be corrupted by:
  • Service outages
  • Crashes
  • Other cases of failure
Example:
  1. Transfer 10$ from A to B.
  2. Valid state: A-10 to B+10
  3. Transaction committed  successfully. 
  4. Power failure occurred 
  5. Checked database after system is up
  6. All changes done by transaction are there. 


Quantum Computing: The Future of Supercomputing Explained

  Introduction Quantum computing is revolutionizing the way we solve complex problems that classical computers struggle with. Unlike tradi...