tezvyn:

ACID: The Four Guarantees of Database Transactions

AI-drafted, machine-checkedSource: Wikipedia: ACIDintermediate

ACID is a contract for database transactions: all-or-nothing guarantees for data validity, even during crashes. It's critical for relational databases in finance or e-commerce. The footgun is assuming all databases offer this; many NoSQL systems don't.

WHY IT EXISTS: Databases manage critical data. If a multi-step operation, like a bank transfer, fails halfway through due to a power outage or bug, the data could be left in a corrupt, invalid state. ACID was created to provide a standard set of guarantees that prevent this, ensuring the database remains a reliable source of truth.

THE MENTAL MODEL: Think of ACID as a legal contract for a single database operation, called a transaction. It has four clauses that must all be met. Atomicity: the whole deal goes through, or none of it does. Consistency: the deal doesn't violate the fundamental rules of the business (like creating money out of thin air). Isolation: two deals happening at once don't interfere with each other. Durability: once the deal is done, it's permanent, even if the power goes out right after.

HOW IT WORKS: ACID is an acronym for four distinct properties that work together. Atomicity: Transactions are 'all or nothing.' If any part of a transaction fails, the entire transaction is rolled back, and the database is left unchanged as if the operation never happened. Consistency: A transaction brings the database from one valid state to another. It can't violate predefined rules, like constraints or triggers. A transfer can't result in a negative account balance if the schema forbids it. Isolation: Concurrent transactions produce the same result as if they were run one after another (serially). This prevents race conditions where one transaction reads the incomplete work of another. Durability: Once a transaction is committed, it will remain so, even in the event of a power loss or crash. The changes are permanently recorded, typically in non-volatile storage like a hard drive.

WHEN TO USE IT: Use ACID-compliant databases when data integrity is paramount. This is the standard for financial systems, e-commerce platforms (managing orders and inventory), and any system of record where correctness outweighs raw performance. Most relational databases (PostgreSQL, MySQL, SQL Server) are strongly ACID-compliant.

WHEN NOT TO USE IT: Strict ACID compliance can create performance bottlenecks, especially in distributed systems at massive scale. Some applications can tolerate eventual consistency. For example, a social media 'like' counter or a logging system might prioritize write availability over the strict guarantees of ACID, making a NoSQL database a better fit.

ONE CANONICAL EXAMPLE: A bank transfer from Account A to Account B. The transaction involves two steps: debiting A and crediting B. Atomicity ensures that if the credit to B fails, the debit from A is rolled back. Isolation prevents another transaction from reading a state where A is debited but B is not yet credited. Durability guarantees that once the transfer is complete, it survives a server crash.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.