• transaction is a single logical unit of work that accesses and possibly modifies the contents of a database.
  • Transactions access data using read and write operations.
  • In order to maintain consistency in a database, before and after the transaction, certain properties are followed. These are called ACID properties
  • In database management systems (DBMS), ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties that ensures the reliability and consistency of transactions. Let’s break down each of the ACID properties:

1. Atomicity:

  • Atomicity ensures that a transaction is treated as a single TASK/ unit of work, meaning that either all of its operations are completed successfully, or none of them are. There are no partial transactions.
  • It involves the following two operations.
  1. Abort: If a transaction aborts, changes made to the database are not visible.
  2. Commit: If a transaction commits, changes made are visible.

Example 1 : Consider the following transaction T consisting of T1 and T2: Transfer of 100 from account X to account Y.

If the transaction fails after completion of T1 but before completion of T2.( say, after write(X) but before write(Y)), then the amount has been deducted from X but not added to Y.

This results in an inconsistent database state. Therefore, the transaction must be executed in its entirety in order to ensure the correctness of the database state.

Example 2 : Consider a bank transfer transaction where money is withdrawn from one account and deposited into another. Atomicity ensures that if the withdrawal succeeds but the deposit fails (or vice versa), the entire transaction is rolled back, leaving both accounts unaffected.

2. Consistency:

Consistency ensures that the database remains in a consistent state before and after the execution of a transaction. Transactions must preserve all integrity constraints and business rules, ensuring that the database remains valid at all times.

Example: If a transaction violates a primary key constraint or a foreign key constraint, it will be aborted, and the database will remain in a consistent state.

3. Isolation:

Isolation ensures that concurrent execution of transactions results in a state that is equivalent to executing them serially, one after the other. Each transaction operates independently of other transactions, and their intermediate states are hidden from each other until they are committed.

Example: If two transactions are updating the same data concurrently, isolation ensures that one transaction’s changes are not visible to the other transaction until it commits. This prevents interference and maintains data integrity.

4. Durability:

Durability ensures that once a transaction is committed, its effects are permanently applied to the database, even in the event of system failures or crashes. Committed changes must be stored permanently and survive system failures.

Example: After a user confirms a flight booking and the transaction is committed, the booking information must be durable and persisted in the database, even if the system crashes immediately afterward.

Importance of ACID Properties:

  • Reliability: ACID properties ensure that transactions are reliable and consistent, even in the face of system failures, crashes, or errors.
  • Data Integrity: ACID properties help maintain data integrity by enforcing constraints and business rules, preventing data corruption or inconsistency.
  • Concurrency Control: ACID properties provide mechanisms for managing concurrent transactions and preventing interference or conflicts between them.
  • Compliance: ACID properties are essential for compliance with regulatory requirements and industry standards, ensuring that data remains accurate and reliable.