DEV Community

Ujjwal Raj
Ujjwal Raj

Posted on

ACID Properties in Single Transactions Explained

Transaction

It is Illusion that either all process operations within a group complete successfully or none.

Transactions are mainly discussed in two scenarios: single transactions (e.g., in traditional relational databases) and distributed transactions (e.g., in banking systems, where a transaction involves transferring funds from one bank account to another bank's account, managed on different servers).

ACID in single transaction

In this blog, we’ll discuss the ACID properties of transactions on a single machine (e.g., in traditional databases) before moving on to implementation details in the next blog and, later, distributed transaction systems.

Assume a banking server having a SQL database and it recieves several transaction requests from several online customer.

Atomicity

A in ACID stands for Atomicity.

"Atomicity" means that a transaction is indivisible—either it completes fully, or it doesn’t happen at all. For example, if money is transferred from Account A to Account B, the transaction should either debit A and credit B completely or leave both accounts unchanged if any error occurs. It should not happen that Account A is debited without crediting Account B.

Consistency

"Consistency" ensures that a transaction brings the system from one valid state to another. In a banking example, if money is transferred between accounts, the total amount across both accounts should remain the same before and after the transaction. This prevents errors like double-spending or data corruption.

Isolation

"Isolation" ensures that transactions are independent of each other. For instance, many transactions might be processed simultaneously on a bank's servers, but each should act as if it is the only transaction happening at that moment. This prevents conflicts and ensures data accuracy.

Durability

"Durability" means that once a transaction is complete, its effects are permanent. In banking, once a transfer is recorded, it should remain in the system, even if the server crashes. To guarantee durability, data is often replicated across multiple servers. (We will explore replication in more detail in future articles.)

Consistency

ACID properties ensure reliable and consistent transactions by enforcing atomicity, consistency, isolation, and durability. These principles help systems manage transactions accurately, even in cases of failure or high concurrency.

Here are links to my previous posts which I publish every Sunday on distributed systems:

Feel free to check them out and share your thoughts!

Top comments (0)