ACID Properties
Also Known As
ACID
atomicity consistency isolation durability
database transactions ACID
TL;DR
The four guarantees of database transactions: Atomicity, Consistency, Isolation, and Durability.
Explanation
ACID ensures reliable transaction processing: Atomicity — a transaction either fully succeeds or fully rolls back (no partial writes); Consistency — the database moves from one valid state to another, enforcing constraints; Isolation — concurrent transactions don't see each other's intermediate state (controlled by isolation levels: Read Uncommitted, Read Committed, Repeatable Read, Serializable); Durability — committed transactions survive crashes (via write-ahead logging). In PHP, manage transactions explicitly with PDO::beginTransaction(), commit(), and rollBack(), especially when multiple related writes must succeed together.
Diagram
flowchart TD
subgraph ACID
A[Atomicity<br/>all or nothing<br/>no partial writes]
C[Consistency<br/>business rules<br/>always maintained]
I[Isolation<br/>concurrent transactions<br/>don't interfere]
D[Durability<br/>committed data<br/>survives crashes]
end
TRANS[Database Transaction] --> A & C & I & D
FAIL[Power failure<br/>during write] -->|redo log| D
CONC[Concurrent writes] -->|locks + MVCC| I
style A fill:#238636,color:#fff
style C fill:#238636,color:#fff
style I fill:#1f6feb,color:#fff
style D fill:#6e40c9,color:#fff
Common Misconception
✗ All databases claiming ACID compliance provide the same guarantees. ACID isolation levels vary — READ COMMITTED, REPEATABLE READ, and SERIALIZABLE offer progressively stronger guarantees with progressively higher overhead. "ACID compliant" without specifying the default isolation level is meaningless.
Why It Matters
ACID guarantees that database transactions are reliable — without them, concurrent writes can corrupt data, partial failures can leave data in inconsistent states, and reads can see uncommitted changes.
Common Mistakes
- Assuming NoSQL databases are ACID — most sacrifice isolation or durability for performance.
- Not wrapping multi-step operations in a transaction — a crash between steps leaves data inconsistent.
- Using READ UNCOMMITTED isolation — allows dirty reads of data that may be rolled back.
- Relying on application-level locking instead of database transactions for concurrency.
Avoid When
- You need horizontal scalability across distributed nodes — full ACID across shards requires coordination overhead.
- The workload tolerates eventual consistency — sacrificing isolation for availability (BASE model) may be correct.
- Using NoSQL stores that offer only document-level atomicity — do not assume full ACID without verifying.
When To Use
- Financial transactions, inventory management, or any domain where partial writes are catastrophic.
- Any operation touching multiple rows or tables that must succeed or fail atomically.
- Concurrent workloads where isolation prevents dirty reads and phantom reads.
- Systems where durability guarantees are required — data must survive a crash without loss.
Code Examples
✗ Vulnerable
// Two separate queries without a transaction — partial failure leaves inconsistent state
$pdo->exec("UPDATE accounts SET balance = balance - 100 WHERE id = 1");
$pdo->exec("UPDATE accounts SET balance = balance + 100 WHERE id = 2");
✓ Fixed
try {
$pdo->beginTransaction();
$pdo->exec("UPDATE accounts SET balance = balance - 100 WHERE id = 1");
$pdo->exec("UPDATE accounts SET balance = balance + 100 WHERE id = 2");
$pdo->commit();
} catch (Exception $e) {
$pdo->rollBack(); throw $e;
}
References
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
25 Mar 2026
Views
52
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 13
Perplexity 10
Google 5
Ahrefs 3
Unknown AI 3
SEMrush 3
Qwen 1
Also referenced
How they use it
crawler 35
crawler_json 2
pre-tracking 1
Related categories
⚡
DEV INTEL
Tools & Severity
🟠 High
⚙ Fix effort: Low
⚡ Quick Fix
Wrap related database operations in a transaction — if any step fails, rollback ensures the database stays consistent; never leave partial writes committed
📦 Applies To
PHP 5.0+
web
cli
queue-worker
🔗 Prerequisites
🔍 Detection Hints
Multiple related INSERT/UPDATE/DELETE statements without wrapping transaction; partial write possible on error
Auto-detectable:
✓ Yes
semgrep
phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: High
Context: File
Tests: Update