Erdmates Logo
Erdmates
Back to Blog
TransactionsACIDConcurrencyIsolation LevelDatabase

Database Transactions and ACID: A Complete Guide

Understand the four ACID properties (Atomicity, Consistency, Isolation, Durability), concurrency anomalies, and isolation levels through practical examples.

March 13, 20269 min read

What Is a Transaction?

A transaction is a set of database operations that must be treated as a single logical unit — either all succeed or all fail together.

Classic example: Bank transfer

  1. Debit $100 from Account A
  2. Credit $100 to Account B

If step 1 succeeds but step 2 fails, Account A loses money with nothing going anywhere. Transactions prevent this.

BEGIN;
  UPDATE accounts SET balance = balance - 100 WHERE id = 'A';
  UPDATE accounts SET balance = balance + 100 WHERE id = 'B';
COMMIT;  -- Both UPDATEs succeed, changes are permanent
-- Or ROLLBACK;  -- On error, both changes are undone

The ACID Properties

Transactions must guarantee four core properties.

A — Atomicity

All operations in a transaction are all or nothing. If any operation fails, all previously completed operations in that transaction are rolled back.

C — Consistency

The database must move from one valid state to another valid state. All constraints (NOT NULL, UNIQUE, FK checks) must hold before and after the transaction.

I — Isolation

Concurrent transactions must not see each other's intermediate, uncommitted state. Each transaction should appear to execute as if it were the only one running.

D — Durability

Once a transaction commits, its changes are permanent — even if the system crashes immediately afterward. Databases use WAL (Write-Ahead Log) to guarantee this.

Concurrency Anomalies

When isolation is imperfect, these problems can occur:

Dirty Read

Reading uncommitted changes from another transaction.

Non-Repeatable Read

The same query returns different results within a single transaction because another transaction committed a change in between.

Phantom Read

A range query returns a different number of rows when executed twice because another transaction inserted or deleted rows in between.

Isolation Levels

The SQL standard defines four isolation levels. Higher isolation eliminates more anomalies but reduces concurrency and performance.

Isolation LevelDirty ReadNon-Repeatable ReadPhantom Read
READ UNCOMMITTEDpossiblepossiblepossible
READ COMMITTEDpreventedpossiblepossible
REPEATABLE READpreventedpreventedpossible
SERIALIZABLEpreventedpreventedprevented
-- Set isolation level in PostgreSQL
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
BEGIN;
  -- your queries here
COMMIT;

PostgreSQL defaults to READ COMMITTED; MySQL InnoDB defaults to REPEATABLE READ.

Practical Tips

  1. Keep transactions short: Minimize lock contention by ending transactions quickly
  2. READ COMMITTED: Appropriate for most OLTP applications
  3. SERIALIZABLE: Reserve for financial settlement or strict consistency requirements
  4. Explicit transactions: Even with ORMs, define transaction boundaries explicitly

Conclusion

ACID is the foundation of reliability in relational databases. When designing your schema, clarify transaction boundaries clearly, and use Erdmates to visualize the related table structures — this makes choosing the right isolation level and designing effective locking strategies much more straightforward.

Start with Erdmates Today

Start designing databases with our AI-powered ERD editor. Free to use.

Try Free DemoStart for Free

Related Articles

bigint, UUID v4, or UUID v7? How to Choose a Primary Key (with PostgreSQL 18's uuidv7())

Compare bigint, UUID v4, and UUID v7 primary keys, see what PostgreSQL 18's built-in uuidv7() changes, and learn which key to pick for each situation.

Databases Read by AI Agents: Schema Design Principles for the MCP Era

AI agents are increasingly connecting directly to databases through MCP. This post covers how to design names, comments, and constraints so agents don't misinterpret your schema, and how to split permissions safely.

PostgreSQL 19 Preview: Changes That Affect Schema Design and Operations (as of Beta 4)

Ahead of its official release, this post covers the PostgreSQL 19 changes that directly affect table design, migrations, and operations, based on the official release notes (Beta 4). It also looks at features reverted during beta and behavior changes to check before upgrading.

Erdmates Logo
Erdmates

Design databases with natural language and collaborate in real-time with your team using our AI-powered ERD editor.

Service

  • Features
  • Pricing
  • Demo
  • SQL to ERD converter

Resources

  • Blog
  • Help
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
  • Third-Party Provision
Company: Produx|Representative: 최정회
Address: 강원특별자치도 원주시 솔우물2길 4-1 (무실동)
Email: master@erdmates.com
Privacy Officer: 최정회|Hosting Provider: Amazon Web Services

© 2026 Produx. All rights reserved.