Skip to content
Home » Concurrency Control

Concurrency Control


CONCURRENCY CONTROL (Detailed Explanation)

Concurrency Control is a fundamental concept in Database Management Systems (DBMS) and is even more critical in Distributed Databases.
When multiple transactions access the same data simultaneously, concurrency control ensures that the database remains:

Correct
Consistent
Free from conflicts
Serializable

Even when many transactions run together.


WHAT IS CONCURRENCY CONTROL?

Concurrency Control is the process that manages simultaneous execution of transactions in such a way that:

  • The ACID properties of transactions are preserved
  • Database remains consistent
  • No incorrect updates occur due to interference between transactions

It ensures serializability, meaning the result of parallel execution is the same as some serial execution.


WHY IS CONCURRENCY CONTROL NEEDED?

When multiple transactions run without proper control, problems arise:

✔ 1. Lost Updates

Two transactions update the same data, but one update overwrites the other.

✔ 2. Dirty Reads

A transaction reads uncommitted data of another transaction.

✔ 3. Non-Repeatable Reads

Data is changed between two reads of the same transaction.

✔ 4. Phantom Reads

Rows added/deleted by other transactions appear/disappear while a transaction is running.

✔ 5. Inconsistent Analysis

When aggregate values are read while other transactions modify data.

Concurrency Control prevents all these anomalies.


GOALS OF CONCURRENCY CONTROL

✔ Maintain database consistency
✔ Ensure isolation between transactions
✔ Guarantee serializability (correctness)
✔ Manage locks and avoid deadlocks
✔ Maximize transaction throughput
✔ Avoid unnecessary delays


TYPES OF CONCURRENCY CONTROL TECHNIQUES

Concurrency control techniques are broadly divided into:

  1. Lock-Based Protocols
  2. Timestamp-Based Protocols
  3. Optimistic Concurrency Control
  4. Multi-Version Concurrency Control (MVCC)
  5. Validation-Based Protocols
  6. Deadlock Handling Techniques

Let’s discuss each in detail.


1. LOCK-BASED CONCURRENCY CONTROL

A lock is a mechanism that restricts access to a data item.

Two main types:

A. Shared Lock (S-lock / Read Lock)

  • Allows read-only access
  • Multiple shared locks allowed

B. Exclusive Lock (X-lock / Write Lock)

  • Allows read + write
  • Only one X-lock allowed
  • No other lock can coexist

TWO-PHASE LOCKING PROTOCOL (2PL)

(VERY IMPORTANT for exams)

2PL ensures serializability using two phases:

Phase 1: Growing Phase

  • Transaction obtains all required locks
  • No locks are released

Phase 2: Shrinking Phase

  • After releasing the first lock, no new lock can be obtained
  • Only unlock operations allowed

Types of 2PL

✔ a) Basic 2PL

Follows two phases strictly.

✔ b) Strict 2PL

  • Locks are held until transaction commits
  • Prevents cascading aborts

✔ c) Rigorous 2PL

  • All locks released only at commit
  • Strongest form of 2PL

Advantages

✔ Ensures serializability
✔ Widely implemented

Disadvantages

✘ Deadlocks possible
✘ Blocking/waiting overhead


2. TIMESTAMP-BASED CONCURRENCY CONTROL

Each transaction gets a timestamp when it starts.

✔ Rules:

  • Older transactions get priority
  • Database ensures that conflicting operations follow timestamp order

✔ Types:

  • Basic Timestamp Ordering (TO)
  • Strict Timestamp Ordering

✔ Advantages:

✔ No deadlocks
✔ Simple to implement

✔ Disadvantages:

✘ More rollbacks
✘ Requires timestamp management


3. OPTIMISTIC CONCURRENCY CONTROL (OCC)

Assumes that conflicts are rare.

✔ Phases:

  1. Read Phase – Transaction executes freely.
  2. Validation Phase – Check for conflicts.
  3. Write Phase – If validation succeeds, commit; else rollback.

✔ Advantages:

✔ High performance in low-conflict environments
✔ No locking → no deadlocks

✔ Disadvantages:

✘ Rollbacks increase during high contention

Used in distributed & mobile databases.


4. MULTI-VERSION CONCURRENCY CONTROL (MVCC)

(Used by PostgreSQL, Oracle, MySQL InnoDB)

Maintains multiple versions of data items:

✔ Readers get a snapshot (no waiting)
✔ Writers create new versions

✔ Benefits:

✔ High read performance
✔ No read locks required
✔ Non-blocking reads

✔ Drawbacks:

✘ More storage
✘ Complex garbage collection for old versions


5. DEADLOCK HANDLING

Concurrency control protocols must manage deadlocks.

✔ Deadlock Prevention

  • Wait-die protocol
  • Wound-wait protocol

✔ Deadlock Detection

  • Wait-for graph
  • Cycle detection

✔ Deadlock Recovery

  • Abort a transaction
  • Rollback and restart

6. DISTRIBUTED CONCURRENCY CONTROL (Important)

In distributed systems:

  • Locks can be maintained globally
  • Distributed timestamp ordering
  • Distributed deadlock detection is more complex

Techniques:

✔ Distributed 2PL
✔ Distributed Timestamp Ordering
✔ Token-based methods
✔ Distributed Wait-for graph


SERIALIZABILITY IN CONCURRENCY CONTROL

Two types:

Conflict Serializability

Schedules can be transformed to a serial schedule by swapping non-conflicting operations.

View Serializability

Weaker but more flexible; ensures final write/read dependencies match serial execution.

Concurrency control aims to achieve serializable schedules.


ADVANTAGES OF CONCURRENCY Control

✔ Improved system performance
✔ Allows multi-user environment
✔ Prevents anomalies
✔ Ensures correctness
✔ Manages resource usage efficiently


DISADVANTAGES

✘ Overhead of lock management
✘ Possibility of deadlocks
✘ Rollbacks in optimistic methods
✘ More complex with distributed systems


Perfect 5–6 Mark Short Answer

Concurrency control ensures that multiple transactions executing simultaneously do not interfere with each other and that the database remains consistent. It prevents problems such as lost updates, dirty reads, and inconsistent states. Concurrency control techniques include lock-based protocols (2PL, strict 2PL), timestamp ordering, optimistic concurrency control, and multiversion concurrency control (MVCC). These techniques ensure isolation and serializability and handle issues like deadlocks and rollbacks.