Transaction Processing and ACID Properties
Before coming to the ACID properties. Let’s get some idea about the transaction Processing and transaction processing system.
What is a transaction?
Group of the task that needs to be completely processed as a single task
eg: Money Transfer, Airline Reservations, Stock Market Transactions
What is a Transaction processing System(TPS)?
If there is a system that has large DATABASES and a large number of concurrent users who execute TRANSACTIONS, that kind of system can be identified as a Transaction Processing System.
eg- Banking System, Airline Reservation System, Stock Market Transaction System
ACID Properties(Transaction Properties)
Atomicity — Transaction should be completely performed or not performed at all.
Which means there is no partially performed transaction.
Consistency Preservation — This is about database consistency. before and after the database must be constant.
Example :
Let say the bank has 7 Million dollars and there is one customer (A) who does a transaction to customer (B) 1Milion Dollars. When a transaction is performed, the balance of customer A’s account will be reduced by 1Milion, and the balance of customer B’s account will be increased by 1Milion Dollars but the total money that the bank has doesn’t change. still, it is 7 Million Dollars. That is DATABASE consistency.
When does that consistency break? Above example, the scenario can be divided into 2 parts,
1.Reducing 1 Milion amount from A’s account
2.Increasing the B’s account balance by 1 Milion
Let assume task 1 is completed and there is an error that happened during the processing of task two and finally that task is not performed. In that kind of situation A’s account balance will be reduced by 1 million dollars but B’s account balance will not be changed. then the total money that the bank has reduced to 6Milion dollars. This is the situation that breaks the consistency property of the transaction processing system.
Isolation — All transactions must be performed independently without the interference of others.
Example:
Let A and B simple transactions processes.
Imagine a situation process B is started when executing process A’s line 2.
when process B read the value of X, process B read an incorrect value. because after process A is finished value of X must be changed to some other value. That’s why all transactions need to be isolated.
Durability: After the transaction is performed all the modifications must be stored in the DATABASE no matter what happened. which means the effect of the transaction must never lose
.
Database Transaction Processing
As I mentioned earlier a transaction is an executing program that forms a logical unit of database processing. from the beginning to the end of the process, Transactions are going through a few states.
State Diagram Of Transition Processing
The active state of the transaction begins with the execution of the transaction.
When transactions become the active state transaction can run a read and write operation with the database.
After completion of the Read and Write operation transaction becomes a partially committed state.
Then recovery protocols need to ensure that a system failure will not result in an inability to record changes in the transaction permanently.
If that check is a success, the transaction comes to the committed state. If that failed, the transaction goes to the Failed state.
The transaction should be rolled back to undo the effect of its write operations on the database.
The terminated state refers to the transaction leaving the system