ACID Properties in Transactions, DBMS

Introduction

When dealing with databases or talking about transactions, system design etc; the term ACID property is very commonly used. In the lite blog, we will learn about ACID property with a simple example. This is a very simple tutorial on ACID properties.

A transaction is a single logical unit under which a sequence of operations are executed. A transaction reads/updates/creates/deletes data in database. ACID properties are a combination of 4 different properties in a database transaction. ACID property ensures the validity and consistency of data in database.

What is transaction and problems around it

A transaction in the DBMS context, is a logical, independent unit of work that is performed to access (read), create or modify (update/delete) information in a database management system. While transaction is the very basic, simple unit of work; it also brings in a lot of complexities in a system.

Running multiple transactions on same set of data, can introduce data inconsistency, lack of data accuracy. Data integrity itself can be compromised; completeness of data is not guaranteed either.

In order to get past these issues around transnational processing, to ensure the database consistency is maintained before and after transactions, ACID property was introduced. ACID is an acronym derived from Atomicity, Consistency, Isolation and Durability.

Let’s take deeper look into each of these properties –

Atomicity

By Atomicity, we ensure that “either everything or nothing” is done. A transaction will be able to do all it’s supposed to do or it won’t do any part of its responsibility. This means that there is no middle path. In another word, a transaction is considered to be a single unit of work; this unit of work is either executed in totality or is not executed at all.
In DB context,
  • a rollback/abort command ensures that all changes by a transaction is discarded and previous stable state is restored. This is an example of transaction doing nothing.
  • a successful commit command ensures that all the changes by the transaction is successful. Database table now represents a new stable state by successful execution of the transaction.
Example:- A has two accounts in a bank. She is transferring X amount from Account-1 to Account-2 in a transaction. Atomicity property ensures that if the amount is deducted from Account-1, the same is credited to Account-2 without fail.
If any error occurs at any stage of the transaction, the transaction will rollback and the account state is kept AS-IS before the transaction started.

Consistency

With the consistency property, a transaction ensures that DB is transformed from one stable/valid/consistent state to another. All the integrity constraints are maintained as part of transaction. This responsibility is mainly with the implementation of code by developer.

Example:- If we take the same example as above, consistency in this transaction will ascertain that the total value of funds in Account-1 and Account-2 remain same before and after transactions.

Isolation

Multiple transactions can run concurrently and it’s ensure that intermediate state of a transaction is not visible to other concurrently running transactions. Concurrent transactions should work as if it were the sole transaction running at one point of time in the system. This also means that transactions will run independently without interfering into each other.
Example:- Continuing the previous example, a transaction T-1 is transferring X amount from Account-1 to Account-2. The isolation property will ensure –
  • Another transaction T-2 sees this X amount in either Account-1 or in Account-2 depending on when actually T-2 is seeing the account details.
  • It will never happen that T-2 sees X amount in both the accounts.
  • It will never happen that T-2 doesn’t see the X amount in both Account-1 or Account-2 at the same time; meaning that X amount is deducted from Account-1 but not credited to Account-2.

Durability

Once a transaction successfully completes, the changes are persisted in the disk and these changes cannot be undone even in case of system failure. In other words, these changes are permanent in nature.

Example:- If we take our example, A transaction successfully transferred amount X from Account-1 to Account-2. The durability property will ensure that the changes made to the accounts won’t be reversed/undone in any circumstance.

 Hope I am able to clear the concept of ACID property through this blog post. Do comment, post, share if you would like to ! 🙂
79

3 Responses

  1. NITISH SHARMA
    December 6, 2018
  2. Sadruddin Md
    December 7, 2018
  3. Gracy Tynoe Mudo
    May 11, 2020

Write a response

This site uses Akismet to reduce spam. Learn how your comment data is processed.