Concurrency Controls in DBMS Ensuring Data Integrity
Concurrency Controls in DBMS Ensuring Data Integrity
Controls 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 practical applications in real-life scenarios.
by Deepali S
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
Concurrency enhances Concurrency can lead to data
performance by allowing inconsistency if not managed
multiple users to access the properly. Transactions can
database simultaneously. It interfere with each other,
enables real-time applications causing issues like lost
that require fast responses updates, dirty reads, and
and data consistency. unrepeatable reads.
Challenges of Concurrent Transactions: Lost
Updates, Dirty Reads, and Unrepeatable Reads
Concurrent transactions can lead to various data integrity issues if not properly controlled. These issues arise from the
interleaving of transactions, where multiple users access and modify data simultaneously. Let's explore three common
challenges:
Locks are the most common Timestamps assign a unique Optimistic concurrency assumes
mechanism for concurrency control. timestamp to each transaction, conflicts are infrequent and allows
They prevent conflicts between allowing the DBMS to track transactions to proceed without
transactions by granting exclusive transaction order and prevent locking until the end, validating and
access to data items to a single conflicts based on timestamp values. resolving conflicts only when
transaction at a time. 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.
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.
1 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.
2 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
Attempts to book the last seat on a flight.
User B
Also attempts to book the last seat on the same flight.
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
Ensures that only one customer can purchase the last
Customer A item, preventing stock depletion conflicts and ensuring
Adds the last item of a product to their cart. data consistency.
1 2 3
Customer B
Also adds the same last item to their cart.
Conclusion: Best Practices and Considerations
for Effective Concurrency Control
Effective concurrency control is essential for modern DBMS to maintain data integrity and ensure reliable transaction
processing. By understanding the challenges of concurrency, choosing appropriate mechanisms, and implementing robust
locking protocols, developers can create reliable and performant database systems. Key best practices include:
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.