3 minute read

In the context of database management systems, ACID (atomicity, consistency, isolation, durability) is a set of properties intended to guarantee that data transactions are reliable and accurate despite of errors, power failures, and other mishaps.

Atomicity

Transactions are often composed of multiple statements. Atomicity guarantees that each transaction is treated as a single “unit”, which either succeeds completely or fails completely: if any of the statements constituting a transaction fails to complete, the entire transaction fails and the database is left unchanged.

An atomic system must guarantee atomicity in each and every situation, including power failures, errors, and crashes.

A guarantee of atomicity prevents updates to the database from occurring only partially, which can cause greater problems than rejecting the whole series outright.

Example: When transferring money from one bank account to another, the whole transaction is made up of two operations. First, you have to withdraw money in one account, and second you have to save the withdrawn money to the second account. Atomicity ensures that if either of those two operations (withdrawing money from the 1st account or saving the money to the 2nd account) fail, the money is neither lost nor created.

Consistency

The Consistency guarantee is related to the accuracy and reliability of the database, and it can be understood in different ways:

  1. If a database is consistent, once a write operation is acknowledged, all subsequent read operations will reflect that write.

  2. If a database using replicas is consistent (to make the system more durable), every replica will be able to reflect the same data at the same time.

  3. If a database transaction is consistent, the transaction may only alter data in allowed ways, given the constraints set for the system. This ensures that the database can only go from one consistent state to another.

Isolation

Isolation ensures that concurrent execution of transactions leaves the database in the same state that would have been obtained if the transactions were executed sequentially.

A low level of isolation enables many users to access the data simultaneously, however this also increases the possibilities of concurrency effects (e.g., dirty reads or lost updates). On the other hand, a high level of isolation reduces these chances of concurrency effects, but also uses more system resources and transactions blocking each other.

To implement these isolation levels, databases use various techniques, including:

  • Locks: Locks are used to block access to data that is being modified by one transaction to prevent other transactions from reading or modifying it simultaneously.

  • Timestamps: Timestamp-based concurrency control assigns a unique timestamp to each transaction. Transactions can read data with timestamps older than their own and write data with timestamps equal to their own. This method ensures isolation by ensuring that transactions do not read or write data that is being concurrently modified.

  • Multi-Version Concurrency Control (MVCC): MVCC creates a snapshot of the database for each transaction, allowing transactions to read a consistent state of the database without blocking other transactions. It’s commonly used in systems like PostgreSQL.

Durability

Durability guarantees that once a transaction has been committed, it will remain committed even in the case of a system failure (e.g., power outage or crash). This usually means that completed transactions (or their effects) are recorded in non-volatile memory and that these systems are resilient to failures in memory.

Some form of replication is usually used to increase durability, so that if one data storage goes down, the data will still be available.

Example: If a flight booking reports that a seat has successfully been booked, then the seat will remain booked even if the system crashes.

Sources

https://en.wikipedia.org/wiki/ACID https://en.wikipedia.org/wiki/Atomicity_(database_systems) https://en.wikipedia.org/wiki/Consistency_(database_systems) https://en.wikipedia.org/wiki/Isolation_(database_systems) https://en.wikipedia.org/wiki/Durability_(database_systems)

Leave a comment