# Transaction

URL: https://softwaredictionary.org/terms/transaction
Category: Databases
Last updated: 2026-09-29

In short: A transaction is a group of database operations that succeed or fail as a single unit, so the data is never left in a half-finished, inconsistent state.

## What is a database transaction?

A transaction bundles several database operations together so they are treated as one all-or-nothing action. If every step succeeds, the changes are saved with a `COMMIT`; if anything goes wrong, a `ROLLBACK` undoes all of them, as if the transaction never happened.

The classic example is a bank transfer: subtracting money from one account and adding it to another must both happen, or neither. Without a transaction, a crash between the two steps could make money disappear. With a transaction, the database guarantees that the two updates are applied together.

Reliable transactions follow the ACID properties. Atomicity means all or nothing; consistency means the data always moves from one valid state to another; isolation means concurrent transactions don't see each other's unfinished work; and durability means committed changes survive crashes and power loss. Databases offer different isolation levels, such as Read Committed and Serializable, which trade strictness for performance.

A database transaction is different from a business transaction like a purchase, although one is often used to record the other. Transactions also get harder in distributed systems such as microservices, where one operation spans several databases; there, teams often use patterns like sagas, a series of local transactions with compensating steps, instead of a single ACID transaction.

## Key takeaways

- A transaction groups operations into one all-or-nothing unit.
- `COMMIT` saves the changes; `ROLLBACK` undoes them.
- ACID stands for atomicity, consistency, isolation, and durability.
- Isolation levels control how concurrent transactions affect each other.

## Example: A bank transfer inside a transaction

```sql
-- Transfer $100 from account 1 to account 2
BEGIN;

UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;

-- Save both changes together
COMMIT;

-- If something had failed, you would run ROLLBACK instead,
-- and neither update would be applied
```

## Frequently asked questions

**What does ACID mean in databases?**

ACID stands for atomicity, consistency, isolation, and durability, the four guarantees that keep database transactions reliable even when errors, crashes, or many simultaneous users occur.

**What is the difference between COMMIT and ROLLBACK?**

`COMMIT` permanently saves all the changes made in the current transaction, while `ROLLBACK` discards them and restores the data to how it was before the transaction started.

**Do NoSQL databases support transactions?**

Many do. MongoDB, for example, supports multi-document ACID transactions, but guarantees and performance vary by database, so check the documentation for your specific system.

## Sources

- [PostgreSQL documentation: Transactions](https://www.postgresql.org/docs/current/tutorial-transactions.html)

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
