Technical Articles

What are ACID properties?

0 0

1. Atomicity
Definition: Atomicity ensures that all operations within a transaction are completed successfully as a whole, or none of them are. If one part fails, the entire transaction fails and the system is rolled back to its previous state.

Real-time Example: Imagine you’re transferring $500 from your bank account (Account A) to your friend’s account (Account B). The transfer involves two steps:

Debit $500 from Account A.
Credit $500 to Account B.
If the debit from Account A is successful but the credit to Account B fails, Atomicity will roll back the debit operation. The result is as if the transaction never happened, ensuring your account is not debited if the transfer fails.

2. Consistency
Definition: Consistency ensures that a transaction takes the database from one valid state to another, adhering to all defined rules (such as constraints, triggers, and data formats).

Real-time Example: Suppose there’s a rule in a retail database that says the quantity of a product cannot be negative. If you attempt to sell more units than are available, the transaction should fail to maintain the rule.

You have 10 units of a product, and you attempt to sell 12 units. The transaction will fail due to the consistency rule, preventing the database from going into an invalid state (negative stock).

3. Isolation
Definition: Isolation ensures that multiple transactions happening at the same time do not interfere with each other. Each transaction should occur independently without affecting the other’s outcome.

Real-time Example: Imagine two customers trying to book the last available seat on a flight. Both users initiate the transaction at the same time. The isolation property ensures that only one transaction can successfully book the seat, and the other user’s transaction will fail.

If two people try to book the last seat on a flight, only one will succeed, while the other transaction will fail or be delayed, ensuring the database remains accurate and no double booking occurs.

4. Durability
Definition: Durability ensures that once a transaction is committed, it will remain permanent, even in the event of a system crash or failure.

Real-time Example: After successfully transferring $500 to your friend’s account (Account B), a power outage occurs. Durability ensures that when the system is restored, the $500 transfer is still recorded and not lost.

After your $500 transfer is completed and committed to the database, even if the bank’s system crashes, the transaction will not be lost, and your friend will still have the credited amount.

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
× How can I help you?