Concurrency Controls in DBMS Ensuring Data Integrity
Concurrency Controls in DBMS Ensuring Data Integrity
Concurrency Controls in DBMS Ensuring Data Integrity
in DBMS: Ensuring
Data Integrity
In the world of database management systems (DBMS), where data
is constantly being accessed and modified by multiple users,
ensuring data integrity and consistency is paramount. Concurrency
control mechanisms are essential for safeguarding data from
corruption and ensuring that transactions are processed reliably,
even when multiple users are accessing the same data
simultaneously. This presentation will delve into the intricacies of
concurrency control, exploring its challenges, mechanisms, and
by Deepali
practical Sin real-life scenarios.
applications
Introduction to Concurrency in
Database Management
Systems
Concurrency in a DBMS refers to the ability of multiple users or
transactions to access and modify data concurrently, without affecting
each other's operations. This is a key feature of modern database
systems, enabling efficient utilization of resources and supporting real-
time applications. However, concurrency introduces challenges that
must be carefully addressed to ensure data integrity.
Benefits Challenges
Locks are the most common Timestamps assign a unique Optimistic concurrency
mechanism for concurrency timestamp to each transaction, assumes conflicts are
control. They prevent conflicts allowing the DBMS to track infrequent and allows
between transactions by transaction order and prevent transactions to proceed without
granting exclusive access to conflicts based on timestamp locking until the end, validating
data items to a single values. and resolving conflicts only
transaction at a time. when necessary.
Isolation Levels: READ UNCOMMITTED, READ COMMITTED,
REPEATABLE READ, and SERIALIZABLE
Isolation levels determine the degree of isolation between transactions, defining how transactions interact with each other. Each
isolation level provides a different level of protection against data inconsistency problems, with higher levels offering greater
protection but potentially impacting performance.
Isolation Level Description
READ UNCOMMITTED Transactions can read data that has not yet been committed,
exposing them to dirty reads.
READ COMMITTED Transactions can read data that has been committed, avoiding
dirty reads, but still susceptible to unrepeatable reads.
REPEATABLE READ Transactions can read the same data consistently throughout
their duration, preventing unrepeatable reads but not
phantom reads.
SERIALIZABLE Transactions are isolated as if they were executed
sequentially, providing the highest level of protection against
data inconsistencies.
Locking Protocols: Strict Two-Phase Locking (S2PL)
and Strict Strict Two-Phase Locking (SS2PL)
Locking protocols define the rules for acquiring and releasing locks during transactions. These protocols help
prevent data inconsistencies by ensuring that transactions access and modify data in a controlled manner. Here are
two common locking protocols:
Strict Two-Phase Locking (S2PL)
A transaction cannot release any lock until it has completed all its operations and committed. This
ensures that a transaction's modifications are visible to other transactions once it commits, avoiding
lost updates.
An extension of S2PL that requires a transaction to hold all locks until it commits, preventing any other
transaction from modifying data that the current transaction is accessing.
Real-Life Example: Airline Reservation
System and Concurrency Control
Imagine an airline reservation system where multiple users are booking flights simultaneously.
Without proper concurrency control, issues like overbooking can arise. When two users try to
book the last seat on a flight, one user might book it first while the other user tries to book the
same seat, leading to overbooking. This scenario highlights the importance of concurrency
control to prevent data inconsistencies and ensure accurate booking.
User A
User B
Concurrency Control
Prevents both users from booking the same seat simultaneously, ensuring data integrity.
Real-Life Example: E-Commerce Platform and
Concurrency Control
E-commerce platforms experience high concurrency with multiple users accessing the same products and making
purchases. Without robust concurrency control, issues like stock depletion conflicts and inconsistent inventory records can
occur. Consider a scenario where two customers try to buy the last item of a product. If concurrency control is not
implemented, both customers might add the item to their carts, leading to a conflict when one customer attempts to
checkout, potentially encountering an "out of stock" message even though they had added it to their cart.
Concurrency Control
Customer A
Ensures that only one customer can purchase the last
Adds the last item of a product to their cart. item, preventing stock depletion conflicts and ensuring
data consistency.
1 2 3
Customer B
By adhering to these best practices, developers can effectively manage concurrency in their database
systems, ensuring data integrity and supporting reliable applications in a multi-user environment.