DEV Community

Marchell Imanuel
Marchell Imanuel

Posted on

ACID

ACID is an acronym for:

  1. Atomicity
  2. Consistency
  3. Isolation
  4. Durability

It is a safety guarantee a database gives us. Most of the time, if it cannot satisfy these safety guarantees, it would rather to abort a transaction than allow it half-finished.

Atomicity

In general, Atomic means a process cannot be broken down to a smaller unit.

Changes in a transaction will be applied completely, or nothing at all. Partial changes is not exists if transaction is used.

Consistency

Data in the database should always in a "good state". The goodness of the data is mostly application specific, but the database can help to some extend: foreign keys, null check, data type enforcement, uniqueness constraint.

Isolation

Multiple transaction will not affecting each other, and will look like as if they are executed serially.

     T1                  T2                DB
     |                   |                 |
     BEGIN               BEGIN             |
     |                   |                 |
     | READ(A)           |                 |
     |------------------------------------>|
     |                   |                 |
     |                   |                 |
     |                   |                 |
     |                   | READ(B)         |
     |                   |---------------->|
     |                   |                 |
     | UPDATE(A)         |                 |
     |------------------------------------>|
     |                   |                 |
     |                   | UPDATE(B)       |
     |                   |---------------->|
     |                   |                 |

Enter fullscreen mode Exit fullscreen mode
  • Transaction T1 reads the value of a data item, which is 10.
  • Before T1 can update the data item, transaction T2 updates the same data item with a new value of 20 and commits the transaction.
  • T1 updates the data item with the old value of 10, overwriting the value of 20 set by T2.
  • This violates the ACID property of isolation, as there is a risk of interference and inconsistency in the data when multiple transactions (T1 and T2) are accessing the same data item without proper isolation.

Durability

The easiest between them. Everything that has been commited stays even between hardware/network failures.

References:

Top comments (0)