Published on 2nd Jul 2021
2 min read
In this short essay, we dive deep and understand the "C" in ACID - Consistency.
In this quick read, we will take a detailed look into Consistency, understand its importance, functioning, and how the database implements it.
In the context of databases, Consistency is Correctness, which means that under no circumstance will the data lose its correctness.
Database systems allow us to define rules that the data residing in our database are mandated to adhere to. Few handy rules could be
An ACID-compliant database engine has to ensure that the data residing in the database continues to adhere to all the configured rules. Thus, even while executing thousands of concurrent transactions, the database always moves from one consistent state to another.
Database Engine rollbacks the changes, which ensures that the database is reverted to a previous consistent state.
Database Engine will continue to apply the changes, and once the transaction is marked successful, this state of the database becomes the newer consistent state.
The answer is very relatable. Would you ever want your account to have a negative balance? No. This is thus defined as a rule that the database engine would have to enforce while applying any change to the data.
Integrity constraints are checked when the changes are being applied to the data.
Cascade operations are performed synchronously along with the transaction. This means that the transaction is not complete until the primary set of queries, along with all the eligible cascades, are applied. Most database engines also provide a way to make them asynchronous, allowing us to keep our transactions leaner.
✨ Next up is "I" in ACID - Isolation. Stay tuned.