Introduction to Transaction Concepts and Concurrency Control
Introduction to Transaction Concepts and Concurrency Control
1. Transaction Processing Systems
Modern database systems often support large databases with many users accessing them simultaneously. Such systems are called transaction processing systems.
Examples include:
-
Airline reservation systems
-
Banking systems
-
Credit card processing
-
Online shopping systems
-
Stock market systems
-
Supermarket checkout systems
These applications require:
-
High availability
-
Fast response time
-
Support for hundreds or thousands of concurrent users
To manage these operations correctly, databases use the concept of transactions.
2. Concept of a Transaction
A transaction is a logical unit of database processing that must be executed completely and correctly.
A transaction usually consists of several database operations such as:
-
Read (retrieving data)
-
Insert
-
Update
-
Delete
These operations are typically executed by a database program or application.
Example
In a bank transfer, the transaction may involve:
-
Deduct money from Account A
-
Add money to Account B
Both operations must succeed together. If one fails, the entire transaction must be undone.
3. Need for Correct Transaction Execution
A transaction must be executed in its entirety to maintain database correctness. If a transaction stops halfway (due to failure or system crash), the database may become inconsistent.
Therefore, database systems ensure that transactions execute correctly using certain mechanisms.
4. ACID Properties of Transactions
Transaction processing systems follow four important properties called ACID properties:
| Property | Meaning |
|---|---|
| Atomicity | A transaction is executed completely or not at all. |
| Consistency | The database remains in a valid state before and after the transaction. |
| Isolation | Transactions executing at the same time do not interfere with each other. |
| Durability | Once a transaction is committed, its changes are permanent. |
These properties ensure reliable and correct database operations.
5. Single-User vs Multiuser Database Systems
Single-User System
-
Only one user can access the database at a time.
-
Mostly used in personal computer systems.
Multiuser System
-
Many users access the database simultaneously.
-
Common in real-world systems like banks and airline reservations.
In multiuser systems, multiple transactions may run concurrently.
6. Concurrent Execution of Transactions
Concurrency means multiple transactions executing at the same time.
This is possible because of multiprogramming in operating systems.
How Multiprogramming Works
A CPU cannot execute multiple processes simultaneously (with a single processor). Instead, it:
-
Executes part of Process A
-
Switches to Process B
-
Returns to Process A
-
Continues switching between them
This is called interleaved execution.
Advantages:
-
Better CPU utilization
-
Faster response time
-
Supports multiple users
7. Concurrency Control
When many transactions run concurrently, they may interfere with each other.
For example:
-
Two users updating the same bank account simultaneously.
-
One transaction reading data while another transaction is modifying it.
These situations can produce incorrect or inconsistent results.
To avoid this problem, the DBMS uses concurrency control mechanisms.
Purpose of Concurrency Control
Concurrency control ensures that:
-
Transactions execute correctly
-
Data consistency is maintained
-
Conflicts between transactions are avoided
It ensures that concurrent execution produces results equivalent to serial execution (one transaction after another).
8. Transaction Failures and Recovery
Transactions may fail due to several reasons:
-
System crash
-
Power failure
-
Software errors
-
Hardware failures
-
Deadlocks
When a failure occurs, the database must be recovered to a correct state.
Database systems use recovery techniques to:
-
Undo incomplete transactions
-
Restore the database to its last consistent state
9. Summary
Transaction processing is essential for reliable database operations in multiuser systems.
Key concepts include:
-
Transactions: Logical units of database work
-
ACID properties: Ensure reliability and correctness
-
Concurrency control: Prevents interference between transactions
-
Recovery mechanisms: Restore database after failures
Together, these concepts ensure that database systems remain accurate, consistent, and reliable even with many users accessing the data simultaneously.

Comments
Post a Comment