Consistency

Learn about the consistency guarantee in ACID transactions.

We'll cover the following

Consistency guarantees ensure that the database moves from one valid state to another. During a transition phase, the database ensures it satisfies all the rules and constraints.

Consistency is a user-defined guarantee. The responsibility of defining the rules and constraints lies with the application developers. Therefore, the database doesn’t play a significant role in maintaining consistency guarantees.

Let’s take a look at some different scenarios to explain this guarantee.

Scenario 1

Person A transfers $100 to person B. Person A’s balance before the transaction was $300 and person B’s balance before the transaction was $400. Consistency guarantees should ensure that the sum of the balances before the transaction should be equal to the sum of balances after the transaction.

  • Sum of balances before the transaction: $300 + $400 = $700.

  • After the transaction, person A’s balance decreases to $200 and person B's balance increases to $500.

  • The sum of balances after the transaction: $200 + $500 = $700.

To ensure this guarantee, the application developer has to wrap up the debit and credit operations in a database transaction between START and COMMIT.

Get hands-on with 1400+ tech skills courses.