Skip to Content
Software EngineeringSystem DesignTopicsACID: properties of transactions

ACID: properties of transactions

What is it

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

  • Atomicity:
    • All changes to data are performed as if they are a single operation. That is, all the changes are performed, or none of them are (all-or-none). If the transaction fails, the database will roll back the transaction.
    • For example, in an application that transfers funds from one account to another, the atomicity property ensures that, if a debit is made successfully from one account, the corresponding credit is made to the other account.
    • 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.
  • Consistency:
    • The transaction doesn’t leave part of the data committed if the transaction fails.
    • Data is in a consistent state when a transaction starts and when it ends.
    • For example, in an application that transfers funds from one account to another, the consistency property ensures that the total value of funds in both the accounts is the same at the start and end of each transaction.
    • 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.
  • Isolation:
    • The transaction keeps other transactions from accessing or writing to the same data until finished.
    • The intermediate state of a transaction is invisible to other transactions. As a result, transactions that run concurrently appear to be serialized.
    • For example, in an application that transfers funds from one account to another, the isolation property ensures that another transaction sees the transferred funds in one account or the other, but not in both, nor in neither.
  • Durability:
    • After a transaction successfully completes, changes to data persist and are not undone, even in the event of a system failure.
    • This implies that updates to the database are stored in and written to disk and they persist even if a system failure occurs. These updates now become permanent and are stored in non-volatile memory.
    • For example, in an application that transfers funds from one account to another, the durability property ensures that the changes made to each account will not be reversed

How is it used

  • Many resources will claim that relational databases have good ACID properties. However, ACID is a very high-level term that isn’t necessarily unique to relational databases.
  • For example, it’s possible to have transactions on a row or document level in a NoSQL database. NoSQL also provides strong durability with replications.
  • So, in an interview, don’t argue for relational databases by saying it’s ACID compliant and other databases are not.
Last updated on