When multiple transactions run at the same time, they may try to read or write the same data item. If not controlled, this can cause lost updates, dirty reads, or inconsistencies.
One of the main ways DBMS avoids this is using lock‑based protocols. In a lock‑based system, a transaction must acquire a lock on a data item before accessing it. This lock acts like a permission that restricts what other transactions can do with the same item.
What Is a Lock?
A lock is a variable associated with a data item (for example, a record, page, or table) that encodes the type of permission a transaction has on that item.
The two basic types of locks are:
Shared lock (S‑lock / Read lock)
Allows a transaction to read the data item.
Multiple transactions can hold shared locks on the same item at the same time.
Exclusive lock (X‑lock / Write lock)
Allows a transaction to both read and write the data item.
No other transaction can hold any lock (shared or exclusive) on the same item while an X‑lock is held.
In simple terms:
Shared lock = “read allowed by many at once.”
Exclusive lock = “write allowed by only one at a time.”
How Locking Prevents Conflicts
Lock‑based protocols enforce rules like:
If a transaction wants to write an item, it must get an exclusive lock.
If another transaction already has an exclusive lock, the requesting transaction must wait.
If a transaction only wants to read, it can get a shared lock, even if other transactions also read.
This prevents conflicting operations (like two writes on the same item) from happening at the same time and helps generate serializable schedules.
Basic Idea of a Lock‑Based Protocol
A lock‑based protocol defines:
What kinds of locks exist (S, X, or more advanced types).
How transactions request locks and how the DBMS grants or denies them.
Rules for growing and releasing locks (often tied to Two‑Phase Locking, which we will see next).
Locking is not a single rigid rule; it is a framework. Different DBMS products customize this framework (adding intent locks, multiple‑granularity locks, etc.) to balance safety, performance, and complexity.
Why Lock‑Based Protocol Matters?
It is one of the most common concurrency control techniques in real databases.
It directly prevents lost updates, dirty reads, and inconsistent analysis by blocking conflicting operations.
It forms the foundation for more advanced ideas like Two‑Phase Locking (2PL) and multiple‑granularity locking, which we will cover next.
Summary
Lock‑based protocol in DBMS is a concurrency control method where transactions must acquire shared or exclusive locks on data items before reading or writing them. Shared locks allow multiple readers, while exclusive locks allow only one writer at a time. By enforcing these lock rules, the protocol prevents conflicts between transactions and helps ensure that concurrent schedules remain serializable and correct.