ACID
It's not a database only feature
ACID isn't a database only feature. Just that database only implements it strictly.
It's a feature of how transactions behave in a system.
- Atomicity - All operations in a transaction are treated as one bundle. Which means, all operations in the bundle will succeed or fail together.
- Consistency - System will always be in a valid state before and after the transaction. Transactions must not break system rules. This means, the system state obeys system's rules after the transaction. For example, any data written to the database must be valid according to all defined rules, including constraints, PK, FK, cascades, and triggers. So only valid data will be written to the database.
- Isolation - Concurrent transactions won't interfere with each other. Which means, any uncommitted transactions won't be visible to other transactions. Locking and MVCC are techniques that provides isolation.
- Durability - Once a transaction is committed, it will remain so, even in the event of power loss, crashes, or errors.
Atomicity meaning
Keep in mind that atomicity in case of programming is different compared to atomicity in case of databases. See Atomic Variables for more details.
Isolation meaning
The database is secretly reordering or controlling operations so it looks like transactions ran one-by-one. This is nothing but serialization.
Isolation vs Concurrency
There is a subtle difference these two topics. Concurrency is about allowing parallel clients access the same data. Whereas, isolation is about ensuring they multiple clients don't corrupt data.
Mental model to remember
Just use a bank transaction to remember the concepts of ACID.
- A - All or nothing
- C - Correct state
- I - Independent transactions
- D - Don't lose committed data