ACID Properties

ACID properties are the standard that helps to maintain consistency in a database on performing every transaction. It means ensuring integrity, consistency of the database before and after every transaction is performed.

ACID properties are one of the most important interview questions. So, better to have an in-depth understanding. Let’s work on it.

ACID stands for Atomicity, Consistency, Isolation, and Durability. Each of them has their roles in DBMS. Before understanding ACID properties, we must know “What is a transaction?”.

What is a transaction?

The transaction is a set of instructions that performs a single logical unit of work in DBMS. The transaction is atomic in nature, either the transaction is fully complete or rollback completely even if it’s a small failure while performing instructions in a transaction. For example, there is a transaction in the bank, in which we have instructions like below:

  • A’s enters a request for money transfer to B’s account
  • Verifying transfer amount exists in A’s account before deduction or A’s eligible or not for this instruction. Suppose it’s yes.
  • The amount is deducted from the bank and goes for transfer to B’s account.
  • The amount deposited B’s bank account successfully.

If one of the instructions is failed and reason is whatever. Then the transaction is considered to be a complete failure. Everything is rollback whatever successfully done.

Atomicity:

This property states that every transaction is an atomic unit which means either all the instructions in a transaction are executed successfully or on the single failure of an instruction considered as a complete failure of transaction even if all other instructions are executed successfully.

As we saw in the above example, there is no sense of partial success in the transaction otherwise DBMS is in an inconsistent state.

Atomicity has two operations:

  • Abort: If the transaction fails/abort, then changes made never be visible.  
  • Commit: If a transaction is successful and committed, changes become visible.

Consistency:

Consistency ensures that any changes during the execution of the transaction don’t bring the database into an inconsistent state.

Isolation:

Isolation ensures integrity between multiple transactions which are running concurrently without interfering with each other. If transactions don’t run independently / separately then there is a complete possibility of inconsistency in DBMS.

Isolation levels define the degree. For Example, one transaction is updating the record which is not committed yet and at the same time another transaction reading the record. So, transactions must isolate from each other as per the degree defined. We have four levels of degree or say isolation level, these are Read Uncommitted, Read Committed, Repeatable Read and Serializable.

Details on Isolation Levels in another article will be share soon.

Durability:

This property makes sure that when a transaction has completed successfully, the changes made to the database like modification of records should exist. There is a possibility of system failure always being there, so in case of system failure just after completion of the transaction, changes should persist and when restarts then the system is returned to the stable state.

Leave a Reply

Your email address will not be published. Required fields are marked *