What is a transaction in computing?
In computing, a transaction is a set of related tasks treated as a single action. Together the tasks form a logical unit of work in which all of them must succeed or none of them can succeed. If some tasks succeed but at least one fails, then all successful tasks are reversed, returning the system to its original state before the transaction -- or job step -- was initiated.
A common example of a transaction is a customer's purchase through an e-commerce site. After selecting a product and entering the necessary information, the customer confirms the final sale by clicking OK or taking some other step to conclude the process. This causes the application to launch a sales transaction, which includes multiple steps, such as confirming the product's availability, validating the credit card, initiating the shipping process and placing the order with the warehouse.
If any steps fail, the entire transaction is rolled back. For example, the product might not be available or the credit card might fail to validate.
In this case, any changes are reverted so everything is returned to its original state. The transaction might also be rolled back because of a disruption in service, such as a database being offline or a server being unavailable. The transaction is committed only after every individual step has been carried out successfully. Changes are then made permanent to the supporting systems, such as updating a database to reflect the new inventory levels.
Transactions and databases
Transactions are commonly associated with databases. Relational database management systems, such as SQL Server and MySQL, include extensive transactional processing capabilities to ensure the integrity of the data. These capabilities are reflected in the Structured Query Language (SQL), a programming language designed to manage database schema and data.
SQL incorporates transaction capabilities directly into its language, providing statements to begin, commit and roll back transactions. When a transaction completes all its operations successfully, the changes are committed to the database; when a transaction does not complete those operations, the changes are rolled back.
Transactions in a relational database typically adhere to the following four ACID properties:
- Atomicity. All operations within the transaction are treated as a single unit. This means that all operations must succeed for any changes to be committed to the database. If any operation fails, no changes are committed, and the entire transaction is rolled back.
- Consistency. The data remains in a consistent state throughout the transaction's execution and is left in a consistent statement at the end of the transaction. The transaction should make no changes that violate any constraints defined on the data.
- Isolation. Each transaction is isolated from all other transactions running concurrently against the database. A transaction should not interfere with another transaction or affect it in any way. The degree to which transactions are isolated from each other is determined by the applicable isolation levels.
- Durability. Any changes made by a transaction after it has been committed are persisted to the database and cannot be undone by outside circumstances, such as a hardware failure or power outage.
Although transaction processing is a vital component in a relational database system, the concept of transaction management is not limited to relational databases. For example, a blockchain is a type of distributed database that serves as a public ledger for recording transactions. A transaction in this sense is a transfer of value between two users on the blockchain's peer-to-peer network. The transaction is validated by the other users on the network and secured through private keys and public keys.
Transactions beyond databases
In computing, the concept of transaction can also extend outside the realm of databases. For instance, IBM's CICS Transaction Server offers a mixed-language application server that provides online transaction management and connectivity. The server supports applications written in a variety of programming languages while providing a platform for hosting transactional enterprise applications in a hybrid environment.
An application in this context is a collection of programs. Each program runs as part of a transaction controlled by the CISC server. In this sense, a transaction is an indivisible operation that combines with other transactions to make up the work.
A program that manages or oversees the sequence of events that are part of a transaction is sometimes called a transaction monitor. A transaction monitor might be included as a component in a larger platform. For example Oracle TimesTen In-Memory Database includes a transaction monitor feature that displays a snapshot of the current transactions and provides details about each one.
Learn about e-commerce trends, tips and traps to avoid and see what IT skills are required for e-commerce.