System Design Tutorial: ACID properties

This tutorial we shall learn about ACID properties.

In this chapter we shall study about what is ACID properties of a transaction and why it is important.

ACID stands for:

1. Automicity
2. Consistency
3. Isolation
4. Durability

Need for ACID properties?

Whenever we need to read or write into DB we need the data to be consistant and we want to maintain it consistant.

How do we maintain the consistency of the data?

We know that, A transaction is sequence of instructions to update a data in DB. Instead of making the DB to be consistent, we can make the transactions to be consistent in-turn making DB to be consistent. Hence if a transaction satisfies the ACID properties, then it will maintain consistency. Hence to make a transaction to be consistant, the transaction should follow ACID properties.

Let us understand in brief about these 4 properties:

1. Automicity

This is the basic property of a transaction. It states that either all the instructions should execute or none of them are executed. This make sense because, if only partial sequence of instructions are executed, then the data will not be consistent.

2. Consistency

This property states if the DB that is consistent state say D1. Then you change change the database state by running a transaction T1. Now the database state will be in state D2. Then according to the consistency property as D1 was in consistent state, hence D2 should also be in consistent state.

3. Isolation

Consider 2 transaction T1 and T2, we say that these 2 transactions are in isolation with each other if they are not effected by each other.

4. Durability

This property states if you have made any changes to the data, that data should be present irrespective of hardware or software failure.

Hence if a transaction satisfies Automicity Isolation and Durability, then the consistency can be easily achieved.

What is a Transaction ?

A transaction is a series of instructions carried out by a single user, that is used to read or update the contents of the database. Once the transaction is completed the DB will reach to a new consistent state. There is an option to rollback the transaction.

What are the States of Transaction:

Active:

When you start a transaction, it will be in active state. It will remain in active state till you perform read or write operation.

Partially Committed: Once the transaction is near to end, it will be in partially committed state.

Committed: From the partially committed state, once you commit the transaction, it will be in committed state. Then that transaction will be in terminated state.

Failed: Failed state can be reached from Active or Partially committed state. During active state or Partially Committed , if you click on abort operation then it will go to failed state.

Terminated: Terminated state can be reached from Committed or Failed state. This is the final state for any transacton. If any transaction reached this state, it means the transaction cycle has ended.

Write a Comment

Leave a Comment

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