๐——๐—ฎ๐˜๐—ฎ๐—ฏ๐—ฎ๐˜€๐—ฒ ๐—”๐—–๐—œ๐——: ๐—ช๐—ต๐—ฎ๐˜ ๐—ถ๐˜€ ๐—–๐—ผ๐—ป๐˜€๐—ถ๐˜€๐˜๐—ฒ๐—ป๐—ฐ๐˜†?

You might think a database handles everything. It does not.

Consistency means your data must follow all rules before and after a transaction. If your rules say a bank balance cannot be negative, a transaction must not leave it at -$50.

Consistency happens at two levels:

  1. Database Level The database enforces technical rules automatically.
  1. Application Level The database does not know your business rules. It does not know your daily withdrawal limit is $30,000. You must write the code to check this.

The Danger: The Lost Update A common mistake happens when you read data, check it in your code, and then write it back.

Scenario:

If both users read the $100 balance at the same time, both checks pass. User A writes $20. User B writes $30. The final balance is $30. The $80 withdrawal from User A is lost. This is a failure of consistency.

How to fix it:

Summary Consistency is your responsibility. Use database constraints for technical rules and use locks or single SQL commands for business logic.

Source: https://dev.to/qq5yu/database-acid-consistency-e5p