0% found this document useful (0 votes)
8 views

Introduction to Concurrency Control

Concurrency control in Database Management Systems (DBMS) ensures that multiple transactions can access or modify data simultaneously without causing inconsistencies, maintaining ACID properties. It addresses challenges like dirty reads, lost updates, and inconsistent reads through mechanisms such as pessimistic and optimistic concurrency control. Future trends include AI-driven management, blockchain integration, and adaptations for real-time applications.

Uploaded by

ghaniashahzad875
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Introduction to Concurrency Control

Concurrency control in Database Management Systems (DBMS) ensures that multiple transactions can access or modify data simultaneously without causing inconsistencies, maintaining ACID properties. It addresses challenges like dirty reads, lost updates, and inconsistent reads through mechanisms such as pessimistic and optimistic concurrency control. Future trends include AI-driven management, blockchain integration, and adaptations for real-time applications.

Uploaded by

ghaniashahzad875
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Introduction to

Concurrency Control

Understanding the Importance,


Challenges and Mechanisms
What is Concurrency Control
Concurrency control is a concept in Database
Management Systems (DBMS) that ensures
multiple transactions can simultaneously access
or modify data without causing errors or
inconsistencies. It provides mechanisms to
handle the concurrent execution in a way that
maintains ACID properties.
What is Concurrency Control

By implementing concurrency control, a DBMS


allows transactions to execute concurrently
while avoiding issues such as deadlocks, race
conditions, and conflicts between operations.
Goal of Concurrency Control
• The main goal of concurrency control is to
ensure that simultaneous transactions do not
lead to data conflicts or violate the
consistency of the database. The concept of
serializability is often used to achieve this goal.
Serializability in DBMS ensures that
multiple transactions can access and
modify the same data without interfering
with each other's operations.
Concurrent Executions

In a multi-user system, several users can access


and work on the same database at the same
time. This is known as concurrent execution,
where the database is used simultaneously by
different users for various operations. For
instance, one user might be updating data while
another is retrieving it.
Challenges in Concurrency Control
Concurrent Execution can lead to various challenges:

• Dirty Reads: One transaction reads uncommitted data


from another transaction, leading to potential
inconsistencies if the changes are later rolled back.
• Lost Updates: When two or more transactions update
the same data simultaneously, one update may
overwrite the other, causing data loss.
• Inconsistent Reads: A transaction may read the same
data multiple times during its execution, and the data
might change between reads due to another
transaction, leading to inconsistency.
Why is Concurrency Control Needed?
Why is Concurrency Control Needed?

Without Concurrency Control:


Transactions interfere with each other, causing issues like lost
updates, dirty reads or inconsistent results.
Without Concurrency Control:
Transactions interfere with each other, causing issues like lost
updates, dirty reads or inconsistent results.
Concurrency Control
Mechanisms
Ensuring
EnsuringData
DataConsistency
ConsistencyininMulti-
Multi-
User Systems
User Systems
Introduction to Concurrency Control
• Concurrency control ensures correct execution
of transactions in a multi-user environment.
• Prevents issues like lost updates, dirty reads,
and inconsistent data.
• Two main types
• Pessimistic Concurrency Control
• Optimistic Concurrency Control
Pessimistic Concurrency Control
• Assumes conflicts will occur, so it
prevents them in advance.
• Methods
• Locking: Prevents other
transactions from accessing data
until the current one finishes.
• Timestamps: Orders transactions
based on timestamps to avoid
conflicts.
• Pros: Ensures high consistency.
• Cons: Can cause delays due to
locks.
Optimistic Concurrency Control
• Assumes conflicts are rare and
resolves them if they occur.
• Methods
• Validation: Checks conflicts before
committing a transaction.
• Multiversion Concurrency Control
(MVCC): Maintains multiple versions
of data to allow concurrent access.
• Pros: Faster for read-heavy
workloads.
• Cons: Can lead to rollback if
conflicts occur.
Which is better?
Feature Pessimistic Control Optimistic Control
Conflict Handling Prevents conflicts upfront Resolves conflicts later
Performance Slower due to locking Faster for reads
Best for High-conflict environments Low-conflict environments

It’s hard to say which is “better”—pessimistic or


optimistic control—because it depends on the
use case.
 Choose Pessimistic Control for high contention databases.
 Choose Optimistic Control for applications with frequent
reads and fewer conflicts.
Hybrid Concurrency Control
• Combines features of both pessimistic and
optimistic methods.
• Example: Using locks for high-contention
transactions and OCC for low-contention
scenarios.
• Used in databases like PostgreSQL
(Multiversion Concurrency Control with locks
for certain cases).
Specialized Concurrency Control
Mechanisms
• Real-time Systems: Priority-based concurrency
control ensures time-critical transactions meet
deadlines.
• Distributed Databases:
– Distributed Locking: Ensures consistency across
multiple nodes.
– Quorum-based Methods: Uses voting mechanisms
for data consistency.
– Eventual Consistency Models: Used in No SQL
databases like Cassandra and DynamoDB.
Concurrency Control in
Distributed system
Ensuring Data
Distributed Consistency
locking in Multi-
mechanisms and
User Systems
distributed transaction mechanisms
Distributed Locking Mechanisms
• A "Distributed Lock Manager" (DLM) is a
software component within a distributed
computing system that manages and
coordinates access to shared resources across
multiple nodes.
• to synchronize access to shared resources,
ensuring data consistency and preventing race
conditions
Types of Distributed Locking Mechanisms:

Centralized Locking:
• A single coordinator (lock manager) maintains
all locks.
• Simple to implement and guarantees
consistency.
Drawbacks: Single point of failure and potential
performance bottleneck.
Example: A central server that grants or denies
lock requests.
Types of Distributed Locking Mechanisms:

• Decentralized (Distributed) Locking:


• Lock management is distributed across multiple
nodes.
• Increases availability and avoids a single point of
failure.
Challenges: Requires complex algorithms to
maintain consistency and avoid deadlocks.
Example: Zookeeper using ZNodes for locks, or
Redis RedLock algorithm.
Distributed Transaction Management
• Distributed Transaction Management ensures
data consistency and integrity across multiple,
distributed databases or systems during
transactions.
• It coordinates operations that span multiple
nodes, ensuring that either all operations
succeed (commit) or none are applied
(rollback)
Distributed Transaction Management
• Two-Phase Commit (2PC):
• Phase 1: Prepare – Coordinator asks
participants to prepare and vote (Commit or
Abort).
• Phase 2: Commit – If all vote Commit, the
coordinator sends Commit; otherwise, Abort.
• Ensures atomicity but can block in case of
coordinator failure.
Distributed Transaction Management
• Three-Phase Commit (3PC):
• Adds an extra phase (Pre-Commit) to avoid
blocking.
• Phase 1: Prepare – Similar to 2PC.
• Phase 2: Pre-Commit – Coordinator ensures all
participants are ready.
• Phase 3: Commit – Final Commit if all are ready.
• Improves fault tolerance but with higher
communication overhead.
Concurrency Control in
Distributed system
Ensuring DataAdvantages,
Challenges, Consistencyand
in Multi-
Future
User Systems
Directions
Challenges in Concurrency Control
✅ Scalability Issues: Managing multiple concurrent transactions
across distributed nodes.
✅ Deadlocks & Resource Contention: Multiple transactions
waiting for resources, causing system delays.
✅ Fault Tolerance: Ensuring consistency despite node failures or
network partitions.
✅ Synchronization Overhead: Increased complexity in
synchronizing multiple nodes.
✅ Latency & Performance Trade-offs: Balancing speed and
accuracy in concurrent processing.
Advantages of Concurrency Control
✅ Improved System Performance – Efficient
execution of multiple transactions without
conflicts.
✅ Data Consistency & Integrity – Ensures data
correctness despite concurrent access.
✅ Increased Reliability – Prevents data loss and
corruption in distributed databases.
✅ Optimized Resource Utilization – Avoids
unnecessary waiting and maximizes throughput.
Concurrency Control in Large-Scale Systems

Example 1: Cloud Databases (Google Drive, Dropbox,


etc.)
• Supports multiple users editing a file at the same time.
• Uses Multi-Version Concurrency Control (MVCC) to
prevent data loss.
Example 3: Ride-Sharing Apps (Uber, Careem, etc.)
• Prevents double-booking of drivers when multiple
users request a ride.
• Uses distributed transaction management to assign
rides properly.
Future Directions & Research Trends

AI-Driven Concurrency Control – Using machine


learning for intelligent transaction management.
Blockchain-Based Transactions – Leveraging
decentralized consensus for distributed systems.
5G & Edge Computing Impact – Adapting
concurrency mechanisms for real-time
applications.
Hybrid Approaches – Combining optimistic and
pessimistic mechanisms for better efficiency.

You might also like