# Database transactions in plain words

> A transaction groups several changes so that either all of them happen or none do. What that protects, what it does not, and the mistakes that make transactions slow or useless.

Source: https://hintvo.com/blog/database-transactions-in-plain-words | Last updated: November 20, 2026 | Reviewed: 2026-11-20

A transaction groups several changes to a database so that either all of them happen or none of them do. Moving money is the standard example: taking it from one account and adding it to another must never be half done.

## The problem it solves

```text
1. Subtract 100 from account A
      the server crashes here
2. Add 100 to account B
```

Without a transaction, the money has left A and never arrived at B. With one, the database undoes the first step when it comes back, as if nothing had happened.

## What it looks like

```sql
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 'A';
UPDATE accounts SET balance = balance + 100 WHERE id = 'B';
COMMIT;
```

Everything between the first line and the last is one unit. If anything fails, a rollback puts the data back as it was.

## The four promises

- **All or nothing.** No half-finished changes.
- **The rules still hold afterwards.** Constraints, such as a balance that cannot go below zero, are checked.
- **Others do not see the middle.** Another request never sees the money gone from A and not yet in B.
- **Done means done.** Once committed, the change survives a crash.

These four are what people mean by the letters ACID.

## What a transaction does not cover

- **Anything outside the database.** An email sent or a card charged in the middle is not undone by a rollback.
- **Two databases or two services.** A transaction belongs to one database.
- **Every timing problem.** Depending on the settings, two transactions can still read the same value and both act on it. See [race conditions](https://hintvo.com/blog/race-conditions-in-plain-words).

## Common mistakes

- Calling an outside service in the middle of a transaction. The transaction stays open while you wait, holding locks.
- Making transactions large. The more rows one touches, the more other requests wait.
- Catching the error and carrying on, so half the work is committed anyway.
- Assuming the framework opened one when it did not.

## Questions you will hear in a meeting

- Are these two writes in one transaction?
- What happens if the second one fails?
- Are we calling anything slow while the transaction is open?

> **Where Hintvo fits:** when a term like this comes up in a call, the In plain words card explains it in one sentence, in the context of your project. When someone asks how your own code handles it, the answer names the file and line.

## Related

- [Race conditions in plain words](https://hintvo.com/blog/race-conditions-in-plain-words.md): What is a race condition, in plain words?
- [Idempotency in plain words: why a retry must not charge twice](https://hintvo.com/blog/idempotency-in-plain-words.md): What does idempotency mean, in plain words?
- [Database migrations in plain words](https://hintvo.com/blog/database-migrations-in-plain-words.md): What is a database migration, in plain words?
