Concurrency Control
Definition
Concurrency control is the set of techniques used in a database management system to coordinate the simultaneous execution of transactions so that the final result is equivalent to some correct serial execution, while preserving database consistency, isolation, and integrity.
In simple terms, it ensures that when multiple transactions run at the same time, they do not interfere with one another in a way that causes errors.
Main Content
1. Need for Concurrency Control
Prevents data anomalies
- When transactions overlap, problems like lost update, dirty read, unrepeatable read, and phantom read can occur. Concurrency control prevents these anomalies and keeps results reliable.
Maintains ACID properties
- Concurrency control is especially important for the Isolation property of ACID. It helps ensure that each transaction behaves as if it is running alone, even though many transactions are executing simultaneously.
A simple example can be understood using a bank account. Suppose Account A has ₹5000. Transaction T1 withdraws ₹1000, and Transaction T2 deposits ₹2000 at the same time. If both transactions read and write without control, one update may overwrite the other. Concurrency control ensures the final balance is correct.
2. Problems Caused by Improper Concurrency
Lost update
- Two transactions update the same data item, and one update overwrites the other. For example, if T1 adds 500 to a balance and T2 adds 300 to the same balance at the same time, one of the changes may disappear if not controlled properly.
Dirty read and inconsistency
- A transaction may read data written by another transaction that has not yet been committed. If the first transaction later aborts, the second transaction has used invalid data. This leads to inconsistent results and possible cascading rollback.
These issues show why concurrent execution cannot be left uncontrolled. A database must provide rules and mechanisms to manage access to shared data safely.
3. Goals and Principles of Concurrency Control
Correctness and serializability
- The main goal is to make concurrent execution produce results equivalent to some serial order of transactions. This is called serializability.
High throughput and minimal waiting
- A good concurrency control method should not only preserve correctness but also allow as much parallelism as possible so that system performance remains high.
For example, if two transactions access different tables, they should ideally be allowed to run simultaneously without unnecessary blocking. Good concurrency control balances safety and efficiency.
Working / Process
1. Transactions request access to data
- A transaction may request to read or write a data item such as a row, page, or table.
- The concurrency control mechanism checks whether the request can be granted safely along with other active transactions.
2. System applies control rules
- Depending on the method used, the system may lock the data, timestamp the transaction, validate its actions, or use a multiversion approach.
- Conflicting operations are delayed, rejected, or reordered to preserve correctness.
3. Transaction completes under isolation rules
- Once the transaction finishes, its changes are committed if valid or rolled back if conflicts or failures occur.
- The final database state remains consistent and equivalent to a correct serial execution.
The process can be represented simply as:
Transaction 1 ---> Request data ---> Control check ---> Read/Write/Wait
Transaction 2 ---> Request data ---> Control check ---> Read/Write/Wait
This ensures that only safe operations proceed when multiple users are working concurrently.
Advantages / Applications
Ensures database consistency
- Concurrency control prevents conflicting updates and preserves the integrity of the database even in heavily loaded systems.
Improves multi-user performance
- It allows many transactions to execute at the same time, which improves resource utilization and response time compared to purely sequential execution.
Used in critical real-world systems
- It is essential in banking, e-commerce, airline booking, ticket reservations, inventory systems, healthcare records, and any system where many users access shared data simultaneously.
For example, in an online ticket booking system, two users may try to reserve the last seat at the same time. Concurrency control ensures that only one reservation succeeds and the other user is informed properly, preventing double booking.
Summary
- Concurrency control manages simultaneous transaction execution safely.
- It helps prevent data conflicts and keeps results correct.
- It is essential for maintaining isolation and consistency in database systems.
- Important terms to remember: transaction, isolation, serializability, lost update, dirty read, locking, timestamp, deadlock