- Atomicity: Each transaction is treated as a single unit, which either succeeds completely, or fails completely.
- Consistency: Each transaction can only bring the database from one valid state to another and always obey database invariants (rules).
- Isolation: Concurrently executing transactions shouldn’t interfere with each other.
- Durability: Once a transaction has committed successfully, any data it has written will not be forgotten, even if there is a hardware fault or the database crashes.
- Basically Available: Basic reading and writing operations are available as much as possible (using all nodes of a database cluster), but without any kind of consistency guarantees (the write may not persist after conflicts are reconciled, the read may not get the latest write).
- Soft state: Without consistency guarantees, after some amount of time, we only have some probability of knowing the state, since it may not yet have converged.
- Eventually consistent: If the system is functioning and we wait long enough after any given set of inputs, we will eventually be able to know what the state of the database is, and so any further reads will be consistent with our expect.
Note: Not only SQL databases are ACID compliant, some of NoSQL databases are fully ACID compliant too, like OrientDB, Neo4j, etc.
- Dirty reads: A transaction reads the data that has not yet been committed by another transaction.
- Dirty writes: A transaction overwrites the data that has not yet been committed by another transaction.
- Read skew (Non-repeatable read): When a transaction reads the same record twice but gets different result each time.
- Lost updates: When two transactions do read-modify-write on the same record concurrently, one of the modifications can be lost (overwritten by another).
- Write skew: Two transactions read the same set of objects, and then update a different subset of those objects concurrently. But the updates violate the rules defined by the application.
- Phantoms: A write in one transaction changes the result of a search query in another transaction.
- Read uncommitted (Lowest)
- Read committed
- Repeatable read
- Serializable (Highest)
Isolation Levels | Dirty reads | Dirty writes | Lost updates | Non-repeatable reads | Phantoms |
---|---|---|---|---|---|
Read uncommitted | May occur | May occur | May occur | May occur | May occur |
Read committed | Avoid | Avoid | May occur | May occur | May occur |
Repeatable read | Avoid | Avoid | Avoid | Avoid | May occur |
Serializable | Avoid | Avoid | Avoid | Avoid | Avoid |
Isolation Levels | Write locks | Read locks | Range locks |
---|---|---|---|
Read uncommitted | None | None | None |
Read committed | Use (release at the end of the transcation) | Use (release just after the SELECT operation is performed) | None |
Repeatable read | Use (release at the end of the transcation) | Use (release at the end of the transcation) | None |
Serializable | Use (release at the end of the transcation) | Use (release at the end of the transcation) | Use |
- Get several nodes to agree on something
- Leader election: All nodes need to agree on which node is the leader.
- Atomic commit: Get all nodes to agree on the outcome of the transaction - Either they all abort or they all commit.
- Uniform agreement: No two nodes decide differently.
- Integrity: No node decides twice.
- Validity: If a node decides value v, then v was proposed by some node.
- Termination: Every node that does not crash eventually decides some value.
- Database-internal distributed transactions: Some distributed databases support internal transactions among the nodes of that database.
- Heterogeneous distributed transactions: The participants are two or more different technologies.
- Book: Martin K.(2017). Chapter 7 Transactions, Designing Data-Intensive Applications (pp. 221-272). O'Reilly Media
- Book: Martin K.(2017). Chapter 9 Consistency and Consensus, Designing Data-Intensive Applications (pp. 321-388). O'Reilly Media
- Web Article: Isolation (database systems) | https://en.wikipedia.org/wiki/Isolation_(database_systems)
- Web Article: Transaction Isolation Levels (ODBC) | https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/transaction-isolation-levels?view=sql-server-ver15