ACID Properties: The Pillar of Reliability in Databases
By William Pereira ·
If you have ever used a banking app or bought a plane ticket online, you have benefited from ACID properties. But what does that mean in practice?
In simple terms, ACID is a set of four principles that ensure transactions in a database (such as a money transfer or a seat reservation) are processed reliably.
1. Atomicity (The "All or Nothing")
Atomicity ensures that a transaction is treated as a single, indivisible unit. Either it happens entirely, or nothing happens at all. There is no "middle ground".
- Practical example: Imagine you are transferring R$ 100,00 to a friend. This operation has two steps:
- Without atomicity: If the system crashes after step 1, the money disappears from your account and never reaches theirs.
- With atomicity: If step 2 fails, the system undoes step 1 automatically (Rollback). Either both steps succeed, or nothing changes.
2. Consistency (Following the Rules)
Consistency ensures that a transaction moves the database from one valid state to another valid state, respecting all predefined rules and constraints.
- Practical example: Imagine a rule in the database that says: "No account may have a negative balance".
- Application: If you try to withdraw R$ 200 but only have R$ 100, the withdrawal transaction will be interrupted because it would violate the consistency rule. The database prevents "corrupted" or invalid data from being saved.
3. Isolation (Each in Their Own Space)
Isolation ensures that, even if several people are using the database at the same time, one transaction does not interfere with another. It is as if each transaction were happening alone in the system.
- Practical example: Two users try to buy the last ticket to a show at the same time.
- Without isolation: Both may see the ticket as available, and the system may end up selling the same seat to two people.
- With isolation: The database "locks" the information for the first user. The second user will only see the result (ticket sold out) after the first user's transaction finishes.
4. Durability (Written in Stone)
Durability ensures that, once the system confirms that the transaction completed successfully (Commit), the data will be saved permanently, even if a power outage occurs or the computer freezes right afterward.
- Practical example: You finish a purchase in an online store and receive the message "Order Confirmed".
- Application: If the store's server blows up a second later, when they turn on the backup server, your purchase should still be registered there. The data was written to persistent storage (disk) and is not only in temporary memory.
Why is ACID important?
Why is ACID important?Data Integrity: It prevents information from being lost or going wrong due to technical failures.Reliability: You can trust that your checking account balance is correct.Safety for the Developer: You do not need to anticipate every possible failure; the database takes care of maintaining basic order.Note on trade-offs: Maintaining these four properties requires computational effort. That is why some modern databases (NoSQL) sometimes give up a bit of ACID in exchange for very high speed, but for financial and critical systems, ACID remains the gold standard.