Graph
Transaction

🔒Transaction

NEW

A unit of work in a database or system executed with ACID guarantees to ensure correctness under concurrency and failures.

DESCRIPTION

Transactions group one or more operations into an atomic unit, committing all changes or none. ACID properties ensure reliable behavior: atomicity, consistency, isolation, and durability. Concurrency control (e.g., locks, MVCC) and logging provide correctness and recovery. Distributed transactions may use two-phase commit or sagas in microservices architectures. Transactions are foundational for financial systems, orders, and inventory, minimizing inconsistencies and anomalies.

ALTERNATIVE DEFINITIONS

PostgreSQL

A transaction is a unit of work performed against a database, treated in a coherent and reliable way independent of other transactions.

Focuses on isolation and reliability as defining aspects.

Source

Oracle

A transaction is a logical, atomic unit of work that contains one or more SQL statements.

Highlights atomicity and composition from multiple SQL statements.

Source

Wikipedia

A database transaction is a unit of work that is performed against a database and treated in a coherent and reliable way independent of other transactions.

Widely cited general definition emphasizing independence.

Source

ACID Atomicity Consistency Isolation Durability Two-Phase Commit Rollback Savepoint Multiversion Concurrency Control

COMPETING TERMS

BASE Saga Pattern

RELATIONS

KNOWLEDGE AREAS

Data Storage & Operations Data Engineering Software Engineering Data Architecture

TARGET AUDIENCE

Software Developer Data Engineer Data Architect Cloud Architect

EXTERNAL SOURCES

  • Wikipedia - Database transaction
  • PostgreSQL - Transaction isolation levels and behavior
  • MySQL - Commit and rollback reference
  • Microsoft - Transact-SQL transaction documentation

TOP QUESTIONS

Why are transactions important in databases?

Transactions ensure correctness, enabling all-or-nothing behavior and consistent results under concurrency and failures. They protect data integrity and simplify application logic.

Category: Relevancy

How do isolation levels affect transactions?

Isolation levels trade concurrency for consistency, controlling phenomena like dirty reads and phantom reads. Choose levels based on workload needs.

Category: Concepts

What is the difference between a transaction and a saga?

Transactions are ACID-bound atomic units; sagas compose local transactions with compensations for long-running, distributed workflows without global locks.

Category: Alternatives

What are common mistakes when using transactions?

Long transactions hold locks excessively, causing contention. Forgetting proper error handling and retries leads to partial failures.

Category: Mistakes

How does MVCC relate to transactions?

Multiversion concurrency control provides snapshot isolation, reducing read-write contention and improving throughput in many workloads.

Category: Concepts

How do distributed transactions work?

They often use two-phase commit to coordinate commits across participants, increasing latency and complexity but preserving atomicity.

Category: Technical

When should I avoid distributed transactions?

When latency and coupling are critical, prefer eventual consistency patterns like sagas and idempotent retries instead.

Category: Decision

What is a savepoint in a transaction?

A savepoint allows partial rollback within a transaction, improving error recovery without aborting the entire unit of work.

Category: Concepts

How can I troubleshoot transaction deadlocks?

Analyze lock graphs and logs, reduce transaction scope, maintain consistent ordering of updates, and add sensible retry logic.

Category: Troubleshooting