intermediatedbms

Transactions and ACID

How databases make sure your data doesn't end up in a half-written, broken state.

Key Points

What it is

A transaction is a group of database operations that are treated as a single unit — they all succeed together or all fail together. ACID is the set of four properties that define what a reliable transaction looks like: Atomicity, Consistency, Isolation, and Durability.

Why it exists

Without transactions, two things can go wrong. First, partial failures: you debit someone's account but crash before crediting the recipient. Second, concurrent access: two users read the same inventory count at the same time, both decrement it, and you end up overselling. Transactions prevent both.

Intuition

The classic example is a bank transfer. You're moving $100 from Account A to Account B. That's two operations: subtract from A, add to B. Without a transaction, if the system crashes after the subtraction but before the addition, the $100 vanishes. With a transaction, either both operations complete or neither does. The money can't just disappear. Isolation is the other half. If two transfers are happening at the same time, they shouldn't interfere with each other's reads. Isolation levels control exactly how much they're allowed to see of each other.

When to use

Common mistakes

Notes

In practice

If you're running data pipelines that write to a database, understanding transactions means you can make your pipeline restartable — if something fails halfway, you roll back and try again without leaving half-loaded garbage. Also relevant in data engineering when loading into OLTP systems.

Was this concept helpful?

Spot an error or gap? Suggest an edit →

Related concepts

sql-basicsindexesrelational-model
Chirp at me!