Info
Open the page on your phone

What is ACID?

ACID is an acronym that stands for Atomicity, Consistency, Isolation, and Durability. These are four key properties that ensure the reliability and predictability of transactions in databases.

  • Atomicity: A transaction either happens completely or not at all. This means that data cannot be partially updated or lost.
  • Consistency: The data in the database always complies with all the defined rules. For example, the balance in an account cannot be negative.
  • Isolation: Transactions are executed independently of each other, without affecting each other. This guarantees that data will not be corrupted or lost due to conflicts.
  • Durability: The changes made by a transaction are stored permanently, even in the event of a system failure.
  •                                    --------------------------------------------------------------

    Achieving ACID depends on the type of database you are using, but generally, there are different methods and mechanisms for each property:

    Atomicity:

  • Journaling: Changes are written to a transaction log before they are applied to the main database. If a transaction needs to be rolled back, the changes can be restored from the log.
  • Snapshots: A copy of the data is created at the beginning of the transaction. If the transaction needs to be rolled back, the snapshot can be restored.
  • Consistency:

  • Constraints: Rules are defined that the data must adhere to (e.g., account balance is always non-negative). The system checks whether a transaction violates any constraints before applying it.
  • Triggers: Special functions (triggers) are automatically executed after certain actions to maintain consistency.
  • Isolation:

  • Locking: A transaction locks access to the data it is using to prevent other transactions from modifying it.
  • Isolation levels: Databases can offer different transaction isolation levels, which control how much data is visible to other transactions while they are running.
  • Durability:

  • Commit protocols: Special protocols ensure that transaction changes are written to disk before it is considered successful.
  • Data replication: Copies of the data are stored on other servers so that they are available in case the main server fails.