MOBI BOOT CAMP CORP. logoLearning Buddy
  • SIGN IN
  • SQL & NoSQL Databases
  • 1. Relational Database Fundamentals
    • Introduction to Databases
    • The Record & Table Structure
    • Data Types
    • Primary & Foreign Keys
    • RDBMS Architecture
    • ACID Properties
    • Normalization (1NF, 2NF, 3NF)
    • Relational Pros and Cons
  • 2. SQL: Basic Data Manipulation (DML)
  • 3. SQL: Filtering and Sorting
  • 4. SQL: Aggregation and Relations
  • 5. SQL: Schema Management (DDL)
  • 6. Python and SQL
  • 7. NoSQL Databases
  • References

ACID Properties

ACID is an acronym that stands for Atomicity, Consistency, Isolation, and Durability. These are a set of properties of database transactions that are essential for guaranteeing data validity and reliability, especially in systems like banking, e-commerce, and finance.

ACID Properties of Transactions

To understand these properties, let's use a Example: a simple bank transfer.

The Scenario

Imagine Alice wants to transfer $100 from her Savings account to her Checking account.

  • Initial Savings Balance: $500
  • Initial Checking Balance: $200

This single transaction requires two separate operations:

  1. Debit: Subtract $100 from the Savings account.
  2. Credit: Add $100 to the Checking account.

Here is how each ACID property ensures this transaction happens correctly.


1. Atomicity (All or Nothing)

What it means: The entire transaction must be treated as a single, indivisible "atom" of work. Either both operations (the debit and the credit) succeed, or neither of them do. There is no middle ground.

The Problem Without Atomicity: What if the system successfully debits 100fromAlice′sSavings(newbalance:100 from Alice's Savings (new balance:100fromAlice′sSavings(newbalance:400), but then a power failure occurs before it can credit the $100 to her Checking account?

  • Savings Balance: $400
  • Checking Balance: $200
  • Result: $100 has vanished into thin air. The bank's records are now incorrect.

How Atomicity Solves It: An ACID-compliant database guarantees that if a transaction is interrupted for any reason, it will be automatically rolled back. The system will undo the initial debit from the Savings account, restoring it to $500. From the database's perspective, the transaction never happened, ensuring that money is never lost or created.


2. Consistency (Data Stays Valid)

What it means: A transaction must bring the database from one valid state to another. Any data written to the database must be valid according to all defined rules, including constraints, cascades, and triggers.

The Problem Without Consistency: A fundamental rule in our banking system is that a transfer should not change the total amount of money, it should only move it.

  • Valid Initial State: Total money = 500(Savings)+500 (Savings) +500(Savings)+200 (Checking) = $700.
  • Invalid State: In the failed transaction scenario above, the total money would become 400+400 +400+200 = $600. This state violates the bank's rules.

How Consistency Solves It: The database enforces consistency. The transaction that would result in an invalid state (like the $600 total) is not allowed to be completed. Consistency ensures that the final state of our successful transaction is also valid:

  • Valid Final State: Savings = 400,Checking=400, Checking =400,Checking=300. Total money = 400+400 +400+300 = $700.

3. Isolation (Transactions Don't Interfere)

What it means: Multiple transactions occurring at the same time should not interfere with each other. The result of concurrent transactions should be the same as if they were executed one after another in some sequential order.

The Problem Without Isolation: Imagine that at the exact moment Alice is making her transfer, the bank is running an automated process to calculate the total interest on all of her funds.

  • The transfer starts: 100isdebitedfromSavings(100 is debited from Savings (100isdebitedfromSavings(400).
  • The interest calculation process runs now. It reads the Savings balance (400)andtheCheckingbalance(400) and the Checking balance (400)andtheCheckingbalance(200, because the credit hasn't happened yet). It calculates interest based on a total of $600, which is wrong.
  • The transfer completes: 100iscreditedtoChecking(100 is credited to Checking (100iscreditedtoChecking(300).

How Isolation Solves It: An ACID-compliant database will "isolate" the two transactions. It ensures that the interest calculation process will see the database either entirely before Alice's transfer began (totaling 700)or∗∗entirelyafter∗∗ithassuccessfullycompleted(totaling700) or **entirely after** it has successfully completed (totaling700)or∗∗entirelyafter∗∗ithassuccessfullycompleted(totaling700). It will never see the inconsistent, intermediate state, thus preventing calculation errors.


4. Durability (Once It's Saved, It Stays Saved)

What it means: Once a transaction has been successfully committed, it is permanent and will survive any subsequent system failure, such as a power outage or crash.

The Problem Without Durability: Alice's transfer completes, and she gets a "Success" notification. Her new balances are Savings: 400andChecking:400 and Checking:400andChecking:300. Immediately after, the database server crashes.

  • When the server reboots, the memory of the transaction might be lost, and her balances could revert to their original state (Savings: 500,Checking:500, Checking:500,Checking:200).

How Durability Solves It: An ACID-compliant database guarantees that as soon as a transaction is committed, its result is written to non-volatile storage (like a hard drive or SSD) in a transaction log. If the system crashes and reboots, it will check this log and ensure that all committed changes are restored, guaranteeing that Alice's transfer is permanent.

Privacy Policy | Terms & Conditions