ACID properties

Anshul vyas
3 min readOct 9, 2018

--

A transaction is a single logical unit of work which accesses and possibly modifies the contents of a database. Transactions access data using read and write operations. To maintain consistency across the database, before and after transactions, ACID properties need to be followed. ACID stands for Atomicity, Consistency, Isolation and Durability.

Atomicity

Atomicity states that a transaction must be treated as an atomic unit, that is, either all of its operations are executed or none. There must be no state in a database where a transaction is left partially completed. It involves the following two operations.

  • Abort: If a transaction aborts, changes made to the database are not visible.
  • Commit: If a transaction commits, changes made are visible.

Atomicity is also known as the ‘All or nothing rule’. The atomic system must guarantee atomicity in each and every situation, including power failures, errors and crashes.

Consistency

Consistency states that the database integrity constraints must be maintained so that the database is consistent before and after the transaction. It ensures that the transaction can bring the database from one valid state to another valid state. It refers to the correctness of a database. The state of the database shall be consistent before and after any transaction. A consistency constraint is a predicate on data which serves as a precondition, post-condition, and transformation condition on any transaction.

Isolation

Isolation ensures that multiple transactions can occur concurrently without leading to inconsistency of database state. Transactions occur independently without interference. Changes occurring in a particular transaction will not be visible to any other transaction until that particular change in that transaction is written to memory or has been committed. This property ensures that the execution of transactions concurrently will result in a state that is equivalent to a state achieved these were executed serially in some order. These employes a locking mechanism to deal with concurrent transactions.

There are various degrees of isolation as stated by Jim Gray:

  • degree 0 — a transaction does not overwrite data updated by another user or process (“dirty data”) of other transactions
  • degree 1 — degree 0 plus a transaction does not commit any writes until it completes all its writes (until the end of the transaction)
  • degree 2 — degree 1 plus a transaction does not read dirty data from other transactions
  • degree 3 — degree 2 plus other transactions do not dirty data read by a transaction before the transaction commits.

Durability

Durability ensures that once the transaction has completed execution, the updates and modifications to the database are stored in and written to disk and they persist even is system failure occurs. These updates now become permanent and are stored in a non-volatile memory. The effects of the transaction, thus, are never lost. The recovery-management component of database systems ensures the durability of the transaction. The several features to consider for durability:

  • recovery to the most recent successful commit after a database software failure.
  • recovery to the most recent successful commit after an application software failure.
  • recovery to the most recent successful commit after a CPU failure.
  • recovery to the most recent successful backup after a disk failure.
  • recovery to the most recent successful commit after a data disk failure.

Thus, the ACID properties, in totality, provide a mechanism to ensure correctness and consistency of a database in a way such that each transaction is a group of operations that acts a single unit, produces consistent results, acts in isolation from other operations and updates that it makes are durably stored.

--

--

Anshul vyas

Product Engineer @ GO-JEK Tech | History and Literature Enthusiast |IIITIAN | Nerd | Music Lover |