A database transaction is a sequence of operations that a database management system treats as a single unit of work. A transaction may read data, modify it, or do both. It ends by committing, which establishes its successful completion, or by aborting, which prevents its uncommitted changes from becoming part of the database’s committed state. Transactions allow applications to express operations such as transferring funds, reserving inventory, or recording an order without treating every individual read and write as an independent event.
Transactions address two fundamental difficulties in shared data processing: failures can interrupt an operation partway through, and concurrent operations can interfere with one another. Their guarantees are commonly described by the ACID properties—atomicity, consistency, isolation, and durability—but the precise behavior depends on the database’s isolation level, recovery design, configuration, and transactional scope. A transaction within one database does not automatically include a message sent to another service or a change made to an external file.
Transaction processing connects application semantics with concurrency control, persistent storage, and distributed computing. Its theory explains which combinations of operations are correct; its implementation determines how systems preserve that correctness while supporting large numbers of simultaneous users.
Transaction boundaries and execution semantics
A transaction establishes a boundary around operations that belong to one logical action. In a relational database, those operations commonly consist of SQL statements that query or update tables. Other database models can provide transactions over documents, key–value pairs, graph elements, or combinations of records. The transaction boundary is independent of the physical storage boundary: changing two rows may require updating several data pages, index entries, and log records.
Consider a transfer of 100 units from account to account . The intended state transition is
If the transfer has no fee and both accounts use the same unit, the invariant is
Executing the debit and credit as unrelated operations would permit a crash to leave only one completed. Placing them in a transaction allows the database to commit both changes or abort the operation. Additional application rules, such as a prohibition on negative balances, require appropriate validation and concurrency protection; grouping statements alone does not specify those rules.
An explicit transaction commonly begins with a statement such as BEGIN or START TRANSACTION and ends with COMMIT or ROLLBACK. Exact syntax varies by product. In autocommit mode, each eligible statement normally executes as its own transaction. A single statement can therefore be transactional even when the application never explicitly begins a transaction. Conversely, a session containing many statements is not necessarily one transaction.
A useful abstract lifecycle distinguishes active, committed, and aborted transactions, with intermediate states while completion is being decided. A transaction that has executed its final application statement may still fail during commit. Once the database has durably committed, a subsequent connection failure does not reverse the decision, although it may prevent the client from receiving confirmation. The application’s knowledge of the outcome can therefore differ from the database’s actual outcome.
Savepoints establish intermediate rollback positions within an active transaction. Rolling back to a savepoint normally discards changes made after it without ending the surrounding transaction. Releasing a savepoint is not an independent durable commit: a later rollback of the outer transaction still reverses the surviving work. True nested transactions, where subtransactions have explicitly defined relationships to parent transactions, are a broader concept and are not implied by ordinary savepoint syntax.
Transactional scope also varies by operation. Schema changes, sequence allocation, temporary objects, and interactions with external programs may have special rules. Some systems support transactional schema modification extensively; others implicitly commit around particular commands. Correct interpretation consequently requires distinguishing the logical transaction offered by the product from the wider business operation that invokes it.
ACID properties and application invariants
ACID abbreviates atomicity, consistency, isolation, and durability. These properties describe different aspects of transaction behavior rather than four independent implementation features. A recovery mechanism may support both atomicity and durability, while a concurrency-control mechanism may determine which consistency-preserving application procedures remain safe under simultaneous execution.
Atomicity means that the database does not leave a transaction’s changes partially committed. If a transaction updates 10,000 records and subsequently aborts, its database changes must not remain as a committed subset. This need not mean that the system physically performs every write at one instant. Implementations can record tentative changes, maintain older versions, or undo already written changes while presenting an all-or-nothing logical outcome.
Consistency concerns valid database states. Constraints such as primary-key uniqueness, foreign-key references, and check conditions encode some validity rules directly. Others reside in application logic: for example, a transfer procedure must debit and credit corresponding amounts. In the conventional ACID account, a correctly written transaction takes a valid state to another valid state when executed under suitable isolation. The database cannot infer an unstated business rule or repair an application that updates the wrong account.
Constraint timing matters. An immediate constraint is checked at the relevant statement boundary, whereas a deferrable constraint may be checked at transaction completion. Deferral permits intermediate states that would otherwise be rejected, such as coordinated changes to mutually dependent records, provided the required conditions hold when checking occurs. It does not imply that other transactions are entitled to observe every intermediate state.
Isolation regulates the effects of concurrent execution. The strongest conventional transactional target is equivalence to some serial ordering of transactions, but many systems also offer weaker levels to reduce blocking or coordination. Atomicity alone does not provide isolation: two transactions can each commit all their writes and nevertheless produce an invalid combined result because they made decisions from incompatible observations.
Durability means that committed changes survive the failures covered by the system’s guarantee. Its practical scope depends on which persistent devices, replicas, and failure domains are included. A commit acknowledged only after local persistent logging has a different failure tolerance from one acknowledged after synchronous replication. Settings that acknowledge transactions before a required log flush trade some durability for lower latency.
ACID consistency must also be distinguished from consistency in replicated systems. A replica may lag while each transaction on the primary remains internally valid. Similarly, backups address restoration after losses that ordinary crash recovery may not cover; a transactional log on the same destroyed storage device is not an independent backup. ACID is thus a framework for understanding guarantees, not a claim that every possible failure, application error, or external side effect is automatically handled.
Isolation levels and concurrent anomalies
Serializability is a correctness criterion for concurrent transactions. An execution is serializable if its relevant effects are equivalent to an execution in which the transactions run one at a time in some order. The actual execution may overlap extensively. Serializability does not, by itself, require that this equivalent order follow the real-time order observed by external clients.
A stronger property, strict serializability, combines serializability with real-time ordering: if one transaction completes before another begins, the first must precede the second in the equivalent serial execution. This distinction matters when comparing transactional guarantees with the linearizability of individual operations in distributed systems. Ordinary database documentation does not always use these terms identically, so named guarantees must be interpreted according to their precise definitions.
Weaker isolation permits particular anomalies. A dirty read observes a change made by another transaction that has not committed and might later abort. A nonrepeatable read occurs when a transaction rereads an item and sees a committed change made by another transaction. A phantom concerns a changed set of rows satisfying a predicate—for example, a second query finding a newly inserted reservation within a date range.
The SQL isolation hierarchy traditionally names Read Uncommitted, Read Committed, Repeatable Read, and Serializable. Read Committed excludes dirty reads but can allow successive statements to observe different committed states. Repeatable Read provides stronger protection, but its exact treatment of predicates and concurrent updates differs among implementations. Products may implement a named level more strongly than the standard minimum, or support a different set of levels.
Snapshot isolation gives a transaction a consistent view of committed data associated with a particular logical point and prevents certain conflicting concurrent writes from both succeeding. It is not generally equivalent to serializability. Its characteristic limitation is write skew, in which transactions read overlapping information but update different records.
Suppose a hospital requires at least one of two doctors to remain on call. Two transactions each read that both doctors are available. One removes the first doctor from the roster, while the other removes the second. If their writes affect different rows, both may commit under snapshot isolation, leaving no doctor on call. Each transaction would have been valid in isolation, but their combination violates the rule. Serializable execution would require blocking, aborting, or otherwise preventing that outcome.
Isolation therefore concerns relationships among reads, writes, predicates, and decisions, not simply whether a transaction sees a stable screen of values. Explicit locking or carefully designed updates can protect a particular invariant at a weaker default isolation level, but their correctness depends on covering every relevant execution path. A uniqueness constraint can resolve some races directly; it cannot express every cross-record business condition.
Concurrency-control mechanisms
Concurrency control determines which simultaneous operations may proceed and which must wait or abort. It connects the abstract guarantees of isolation to concrete mechanisms such as locks, timestamps, record versions, and dependency tracking. Different approaches can implement the same isolation level, and practical databases often combine several approaches.
Two-phase locking divides lock acquisition into a growing phase, during which a transaction obtains locks, and a shrinking phase, during which it releases locks without acquiring new ones. Under the appropriate locking model, this discipline ensures conflict serializability. Shared locks generally allow compatible readers, whereas exclusive locks protect writes. Strict two-phase locking retains exclusive locks until transaction completion; implementations that retain all transaction locks until completion provide an even stronger lock-retention discipline.
Locking must protect more than existing rows when a transaction relies on a predicate. If a transaction verifies that no reservation overlaps a time interval, locking only the rows currently found may leave another transaction free to insert a conflicting reservation. Predicate locks or index-range techniques address this problem. A database index can therefore influence not only query speed but also the granularity and scope of concurrency protection.
Blocking introduces deadlock. If transaction holds a lock needed by , while holds a lock needed by , neither can proceed. Systems can detect cycles in a wait-for graph and abort a participant, or use prevention rules based on transaction age or lock ordering. Timeouts provide another escape mechanism, although a timeout does not prove that a deadlock existed.
Multiversion concurrency control, or MVCC, keeps multiple logical versions of data. Visibility rules determine which version a reader may observe, often using transaction identifiers or timestamps. This can let readers proceed without waiting for writers and writers proceed without blocking ordinary snapshot readers. MVCC is not itself an isolation level: it can support Read Committed, snapshot isolation, serializable execution, or other semantics depending on additional rules.
Versions consume storage and eventually require reclamation. A long-running transaction may keep old versions necessary for its snapshot, delaying cleanup even when newer transactions no longer need them. Physical implementations differ: one system may retain old row versions in table storage, another in undo structures. Short-lived internal latches that protect memory structures are also distinct from transaction locks; their purpose and lifetime are different.
Optimistic concurrency control allows tentative work to proceed and validates it before commit. If the observed reads and writes conflict with concurrent activity, the system aborts and retries a transaction. Serializable snapshot isolation similarly detects dangerous patterns of read–write dependencies while using versioned reads. Such techniques can reduce blocking, but under heavy contention repeated aborts consume processing capacity. The appropriate trade-off depends on transaction duration, conflict frequency, read–write balance, and the cost of repeating work.
Logging, recovery, and durable commit
Transaction recovery preserves atomicity and durability when processes stop, machines restart, or writes reach persistent storage in an inconvenient order. Database pages are commonly cached in memory, and the order in which pages are modified need not match the order in which storage writes complete. A recovery protocol must therefore make sense of both missing writes and writes made by transactions that never committed.
Write-ahead logging records recovery information before the corresponding changed data pages are allowed to reach persistent storage. In a common design, commit also requires the transaction’s commit record and preceding log records to be durable before success is acknowledged. The database need not force every modified data page to storage at commit, because recovery can reconstruct the committed changes from the log.
Two buffer-management choices explain important recovery requirements. Under a steal policy, a page containing an uncommitted update may be written to storage; recovery may consequently need to undo that update. Under a no-force policy, commit does not require every changed page to be flushed; recovery may need to redo committed updates. These terms describe storage policies rather than isolation levels.
The ARIES recovery method, published in 1992 by C. Mohan and colleagues, is a major example of log-based recovery designed around such conditions. Its restart procedure includes analysis, redo, and undo. Analysis reconstructs information about active transactions and dirty pages; redo repeats relevant logged history; undo reverses incomplete transactions. Compensation log records document undo work so recovery can itself survive another interruption.
Checkpoints reduce how much earlier activity must be examined during restart. A checkpoint is not necessarily a moment when every transaction stops or every dirty page is immediately written. A fuzzy checkpoint can record sufficient recovery metadata while transaction processing continues. The exact recovery starting point depends on the logging and checkpoint design, not simply on the time of the latest checkpoint marker.
Durable logging also requires coordination with the operating system, the file system, and storage hardware. A write accepted into a volatile cache is not equivalent to a write that survives power loss. Flush commands, ordering barriers, and storage-device guarantees form part of the correctness boundary. Some systems use alternative persistence techniques, such as shadow paging or copy-on-write structures, rather than relying entirely on in-place update and undo logging.
Group commit amortizes persistence cost by allowing several transactions to share a log flush. This improves throughput without necessarily weakening durability: each transaction can be acknowledged after the shared flush completes. However, a client may still lose its connection after the commit becomes durable but before the acknowledgment arrives. Recovery determines the database outcome; it cannot by itself remove that uncertainty from the client’s view.
Transactions across nodes and services
A distributed transaction spans multiple participants, such as database shards or separate resource managers. Its central atomicity problem is ensuring that all participants agree on whether to commit. Successful execution at one participant cannot justify committing there if another participant must abort. Network delay, machine failure, and incomplete knowledge make this harder than coordinating work within one process.
Two-phase commit separates the decision into preparation and completion. In the first phase, a coordinator asks each participant whether it can commit. A participant that votes yes records enough persistent information to honor a later decision and enters a prepared state. If all required participants vote yes, the coordinator can durably decide to commit; otherwise, it decides to abort. The second phase communicates that decision.
A prepared participant cannot simply abandon its commitment because a timeout expires. The coordinator might already have committed and informed other participants. Consequently, classic two-phase commit can block when the decision is unavailable, holding locks or other resources while the participant remains in doubt. Recovery protocols and replicated coordinators can improve availability, but they do not eliminate the need to establish a consistent decision.
Consensus and atomic commit solve related but different problems. Consensus allows a group of replicas to agree on a value despite specified failures; atomic commit coordinates whether work across transaction participants succeeds. A system may use a consensus protocol to replicate each shard’s log and still use a separate cross-shard commit protocol. Replication of transaction data is not automatically equivalent to atomic commitment across independently managed data sets.
Distributed isolation is another independent requirement. Even if every shard commits or aborts together, the combined execution may not be serializable unless reads, writes, and ordering are coordinated appropriately. Google’s Spanner, described in 2012, combined synchronous replication, distributed transactions, and the TrueTime time-uncertainty interface. Its external-consistency design uses timestamp assignment and commit waiting to connect transaction ordering with real time, illustrating that distributed atomicity and ordering require more than a commit vote.
Across microservices, a single database transaction often cannot include every business action. A payment provider, shipping system, and local order database may expose different protocols and availability guarantees. A saga divides a business process into separately committed steps with compensating actions when later steps fail. Compensation is not database rollback: cancelling a shipment or issuing a refund is a new action, and it may not perfectly restore the earlier world.
The transactional outbox addresses a narrower coordination problem by writing business data and an outgoing event into the same local transaction. A separate publisher forwards committed events to a message broker. Forwarding can occur more than once after failures, so consumers commonly need duplicate detection or idempotent handling. The pattern provides a reliable handoff boundary rather than making every downstream effect part of the original transaction.
Application behavior, retries, and external effects
Applications interact with transactions through SQL commands, database drivers, and application programming interfaces. These interfaces expose transaction boundaries but do not remove the need to define what successful completion means. A business operation may consist of database reads, validation, computation, and writes, with each stage potentially introducing dependencies on concurrent activity.
A common error is an unprotected read–modify–write sequence. An application reads a balance of 500, computes 400, and writes 400. Another transaction may have changed the balance after the read, causing the later write to overwrite that change. An expression such as UPDATE accounts SET balance = balance - 100 lets the database perform the modification against the row it updates, avoiding that particular overwrite pattern. Sufficient-funds validation still requires appropriate statement semantics, locking, or isolation.
Conditional updates can combine a test with a state transition. For example, an update may debit an account only where its balance is at least 100, with the application checking that exactly one row was affected. The corresponding credit must remain in the same transaction, and the application must handle missing destinations or other failures before committing. Database constraints provide a further line of enforcement but cannot replace all application-level validation.
Deadlocks, serialization failures, and optimistic-validation conflicts are expected outcomes in many correct systems. A transaction selected for abort has not necessarily exposed a software defect; aborting can be the mechanism that preserves correctness. Repeating only its final failed statement is not always equivalent to repeating the transaction, because earlier reads may have determined later decisions. A retry may need to repeat the entire logical unit using a fresh database view.
Idempotence becomes important when a client cannot tell whether an earlier request committed. Repeating “transfer 100” as a new transaction can create a second transfer. An application can instead associate the operation with a stable request identifier and store that identifier, the business changes, and an appropriate result within the same transactional boundary. A uniqueness constraint then helps ensure that repeated submissions refer to one recorded operation.
External effects require separate treatment. Sending an email or calling a payment service before commit may produce an effect even if the transaction later aborts. Doing so after commit leaves a failure window in which the database change succeeds but the external action does not happen. Outbox processing, durable workflow state, and independently idempotent service operations address different parts of this problem; a local rollback cannot retract an already delivered email.
Connection management also affects transaction correctness. Returning a connection to a pool while it still has an active transaction can leave locks and snapshots alive or expose unexpected session state to later work. Error behavior varies among databases: some statement errors invalidate the transaction until rollback, while others permit continued execution. Transaction-handling code must therefore distinguish statement failure, transaction failure, and uncertainty about an already attempted commit.
Workload design and performance trade-offs
Transaction performance is governed not only by query execution speed but also by contention, logging, coordination, and the duration of protected work. Online transaction processing, or OLTP, commonly involves many short operations over relatively small portions of a database: recording purchases, changing account balances, or maintaining order status. Analytical workloads more often scan large data sets and hold snapshots for longer periods.
Transaction size changes several costs at once. Combining many small writes into one transaction can reduce commit overhead and amortize log flushing. It can also increase lock duration, log volume retained for recovery, memory use, and the amount of work lost after an abort. Dividing a large job into batches limits those costs but changes semantics: other sessions may observe partially completed batches unless an additional publication mechanism hides them.
Contention is often concentrated rather than uniform. A single inventory record, sequence-like counter, or account can become a hot spot even when the database contains billions of unrelated records. Additional processors do not eliminate the need to order conflicting updates to that item. Partitioning spreads independent work, but transactions that cross partitions introduce coordination and may place the bottleneck elsewhere.
A simple queueing relationship helps explain the effects of transaction duration. Under stable operating conditions, Little’s law gives
where is the average number of in-flight transactions, is throughput, and is average time in the system. At 2,000 transactions per second and an average duration of 0.05 seconds, approximately 100 transactions are in flight on average. This does not predict lock behavior by itself, but it shows why longer transaction lifetimes can increase the population competing for resources.
Long-running readers have different effects under different concurrency mechanisms. With locking, they may delay writers or require broader protection for serializable queries. With MVCC, they may avoid directly blocking writers while preventing old versions from being reclaimed. An idle session that leaves a transaction open can therefore create substantial operational effects despite consuming little processor time.
Benchmarks must specify the transactional contract being measured. Throughput figures are not directly comparable when one configuration uses asynchronous commit, another waits for multiple replicas, and a third omits cross-record isolation. The TPC-C benchmark, approved in 1992, models an order-entry workload with several transaction types; TPC-H targets decision-support queries rather than the same OLTP pattern. Both workload composition and durability rules influence the meaning of reported results.
Performance evaluation also distinguishes successful business transactions from raw attempts. A system may execute many operations while aborting a large fraction under contention. Commit latency, tail latency, retry rate, recovery time, and behavior during participant failure reveal properties that an average throughput figure alone does not capture.
Historical development and theoretical foundations
Database transactions emerged from the requirements of shared commercial data processing, including banking, reservations, and inventory management. Once several users could update persistent data concurrently, correctness could no longer be understood solely by examining one program’s sequential instructions. Systems needed explicit units of recovery and rules for interleaving access to shared records.
During the 1970s, relational database research brought these problems into a systematic framework. IBM’s System R project investigated practical relational query processing together with concurrency control and recovery. In 1976, Kapali Eswaran, Jim Gray, Raymond Lorie, and Irving Traiger published “The Notions of Consistency and Predicate Locks in a Database System,” an influential treatment of how transaction execution and locking relate to database consistency.
Serializability theory supplied a way to reason about interleaved histories independently of a particular program listing. In a conflict graph, transactions form vertices and conflicting operations establish directed edges. For the standard single-version conflict model, an acyclic graph characterizes conflict-serializable histories. This gives both a conceptual test and a basis for proving that a scheduling method preserves a desired execution order.
Jim Gray’s work in the late 1970s and early 1980s helped consolidate transaction processing as a distinct field. Theo Härder and Andreas Reuter introduced the ACID acronym in their 1983 paper “Principles of Transaction-Oriented Database Recovery.” The terminology joined application-level expectations with the recovery and concurrency mechanisms needed to meet them. Gray received the 1998 ACM Turing Award for fundamental contributions to database and transaction-processing research and implementation.
Later developments exposed limitations in treating isolation as a simple ladder of names. Hal Berenson and colleagues’ 1995 paper “A Critique of ANSI SQL Isolation Levels” analyzed ambiguities and gaps in anomaly-based definitions and described snapshot isolation. Work on multiversion serialization theory and dependency analysis further distinguished implementations that provide stable snapshots from those that ensure serializable transactions.
The growth of Internet services and NoSQL databases diversified transactional scope. Some systems emphasized atomic updates to individual records, while others supported multi-record or distributed transactions. NewSQL systems sought relational transactional guarantees together with distributed scale. These categories do not determine a product’s exact guarantees: transactional behavior still depends on the operations, configuration, and isolation semantics actually provided.
Transaction research also intersects with formal verification. Researchers model histories, failure states, replication protocols, and recovery procedures to establish properties that testing alone cannot prove universally. Important distinctions remain between safety—such as never committing an inconsistent outcome—and liveness, such as eventually completing despite failures. A protocol can preserve safety by waiting indefinitely, making availability and progress separate questions from the correctness of its committed results.