A database transaction should satisfy the ACID property to ensure data integrity and reliability. This is a guided rule enforced by developers to ensure that the application functions as expected.
First let us understand the meaning of transaction in database. It is a logical unit of change that achieves a purpose. One transaction may have multiple changes being performed in the database to achieve the required objective.
It becomes all the more important to have proper and consistent transactions being performed in a multi-user and multi-transaction database to ensure data integrity and reliability. A transaction must adhere to ACID property to achieve this.
What is ACID?
It is an acronym for –
As we will see, each of the ACID property complement each other to achieve the final goal.
Atomicity requires each transaction to complete either in total or abort and rollback the change. It is either all or nothing. Atomicity should exist in every condition that affects the transaction, even database failure or some sort of corruption that interrupts the transaction.
Consistency ensures that with every change in data, the database state moves from one valid state to another and all data validity rules are enforced. This ensures that a consistent view of the data is always available to any and all users who access it. Any change done to the data should be valid as per the program needs and set data constraints.
Isolation ensures that each transaction is performed in its own container and does not affect other transactions. Each transaction is carried out in isolation of the other with a consistent view of the data. The changes done by one transaction are not visible to another till the same is completed in total and committed in the system.
Durability ensures that the changes done by a transactions that got committed to the database will not be lost in the event of a power failure, system crash or database aborting.
ACID with an example
Check out the following infographics to understand this concept even more.
Is ACID property guaranteed by a Database?
Each database architecture does its part to ensure the implementation of ACID property. However, a lot depends on the application programmer writing the code as well. A programmer must ensure that these properties are adhered to when writing code that updates backend data. There should be proper gates in the code to complete the transactions successfully or rollback. Hence, ACID is very much a responsibility of the application code and must be ensured at all cost.
When we come across “bugs” or “data corruption” cases – the possibility of ACID property not being imposed in its totality could persist.
Here are some more links related to this subject matter.