Tuesday, August 19, 2008

The ACID test for databases

ACID is an acronym for Atomicity, Consistency,
Isolation, and Durability.
(from http://www-128.ibm.com/developerworks/opensource/library/os-ad-trifecta2/)

Atomicity means that operations with the database can be grouped
together and treated as a single unit.

Consistency guarantees that either all the operations in this single
unit (or transaction) are performed successfully, or none of them is
performed. In other words, a database can't be in an unfinished state.
To understand why these characteristics are important, think about a
bank transaction during which money is transferred from a savings
account into a checking account. If the transfer process fails after
subtracting the money from your savings account and before it was
added to your checking account, you would become poorer, and the bank
would have an angry (ex)customer! Atomicity enables the two operations
-- the subtraction from the savings account and the addition to the
checking account -- to be treated as a single transaction. Consistency
guarantees that both operations in the transaction either succeed or
fail. That way, your money isn't lost.

Isolation means that independent sets of database transactions are
performed in such a way that they don't conflict with each other.
Continuing the bank analogy, consider two customers who transfer funds
between accounts at the same time. The database must track both
transfers separately; otherwise, the funds could go into the wrong
accounts, and the bank might be left with two angry (ex)customers.

Durability guarantees that the database is safe against unexpected
terminations. It may be a minor inconvenience if your television or
computer won't work when the power goes out, but the same can't be
said for a database. If the bank's computers lose power when
transferring your funds, you won't be a happy customer if the
transaction is lost. Durability guarantees that if the database
terminates abnormally during a funds transfer, then when the database
is brought back up, it will be able to recover the transaction and
continue with normal operations.

No comments: