Variations of 2PL Interview Questions: 12 Answers on Strict, Rigorous and Conservative Locking

Prepare basic, strict, rigorous and conservative 2PL with precise definitions, worked schedules, a deadlock proof and interview-ready comparisons.

KnowledgeGate Team

Exam prep & CS education

Updated 6 Nov 20266 min read
Variations of 2PL Interview Questions: 12 Answers on Strict, Rigorous and Conservative Locking

Many candidates can expand 2PL as two-phase locking, yet the interview distinction is when locks are acquired and released. The key traps are dirty reads, cascading rollback, recovery order, deadlock, and preclaiming. Reason from those traces, then practise the same answer-delivery skill in Interview & Resume Preparation Course.

1. Start with basic 2PL: growing phase, shrinking phase and lock point

Q1. What is two-phase locking, and what are its two phases?

In the growing phase, a transaction may acquire or upgrade locks, but may not release or downgrade any lock. After its first unlock or downgrade, it enters the shrinking phase. It may then release locks, but may acquire or upgrade none. The lock point is the instant at which it obtains its final lock.

Take A = 100 and B = 50:

XL1(A), XL1(B), R1(A=100), W1(A=80), U1(A), R1(B=50), W1(B=70), U1(B), C1

XL1(B) is T1's lock point. Both exclusive locks arrive before the first unlock, so this obeys basic 2PL. The result is A = 80, B = 70, and A + B = 150.

Q2. What does basic 2PL guarantee, and what does it not guarantee?

With correct lock compatibility, 2PL guarantees conflict serializability, ordered by lock points. It does not prevent deadlock, dirty reads after an early exclusive unlock, cascading rollback, or a nonrecoverable commit order. Review the wider foundation in DBMS Transactions: ACID, Serializability, 2PL Explained.

2. Strict 2PL: hold write locks to the end and stop cascading rollback

Q3. What makes strict 2PL stricter than basic 2PL?

Strict 2PL follows 2PL and retains every exclusive lock until commit or abort. Shared locks may be released in the shrinking phase, provided the transaction requests no later lock. Holding an exclusive lock blocks both a dirty read and a dirty overwrite of that item. Strict schedules are therefore cascadeless and recoverable.

Q4. Show a schedule that basic 2PL accepts but strict 2PL rejects.

Start again with A = 100, B = 50:

T1: XL(A), XL(B), R(A=100), W(A=80), U(A)

Then T2: SL(A), R(A=80), followed by A1, which restores A = 100. T1 acquired both locks before its first unlock, so basic 2PL permits this. But T2 read the uncommitted 80, so T2 must also abort. If T2 had committed before A1, the schedule would be nonrecoverable, not merely cascading.

Under strict 2PL, T1 cannot execute U1(A) before C1 or A1, so SL2(A) waits. If T1 aborts, it restores A = 100, releases its locks, and T2 reads 100. Separately, if T1 writes B: 50 -> 70 and commits, T2 later reads the committed A = 80.

Side-by-side timelines compare basic and strict 2PL: an early unlock permits a dirty read, while a retained write lock makes the reader wait for commit or abort.

3. Rigorous 2PL: hold read locks as well as write locks until completion

Q5. How does rigorous 2PL differ from strict 2PL?

Strict 2PL keeps every exclusive lock through commit or abort. Rigorous 2PL keeps both shared and exclusive locks through commit or abort. Every rigorous execution is strict, but a strict execution need not be rigorous.

For initial C = 40, consider:

SL3(C), R3(C=40), U3(C), XL4(C), W4(C=45), C4, C3

T3 requests no lock after its unlock, and T4 holds its exclusive lock to commit, so strict 2PL accepts the trace. Its only conflict orders T3 before T4, even though C4 occurs before C3.

Q6. Why does rigorous 2PL simplify commit-order reasoning?

Under rigorous 2PL, T3 retains SL3(C) until C3, so T4's XL4(C) must wait. The legal trace is SL3(C), R3(C=40), C3/release, XL4(C), W4(C=45), C4/release. For this conflicting pair, the serialization order and commit order are both T3 before T4. Unrelated transactions need not have a meaningful fixed order.

4. Conservative 2PL: preclaim the full lock set to remove deadlocks

Q7. What is conservative or static 2PL?

Before executing, a transaction requests its complete lock set. It receives every lock together if all are available. Otherwise, it receives none and waits. The read and write set must therefore be known in advance.

Q8. Prove with a schedule that conservative 2PL is deadlock-free.

Ordinary strict 2PL can deadlock: t1 gives T1 X(A); t2 gives T2 X(B); at t3, T1 requests X(B) and waits; at t4, T2 requests X(A) and waits. The wait-for graph has T1 -> T2 and T2 -> T1.

Conservatively, T1 requests {X(A), X(B)} at t1 and gets both. T2 requests {X(B), X(A)} at t2, gets none, and waits without a lock. T1 transfers 20, giving A: 100 -> 80, B: 50 -> 70, then commits. T2 gets both and transfers 10 from B to A, giving B: 70 -> 60, A: 80 -> 90, then commits. The sum is 90 + 60 = 150. Because a waiting transaction holds no lock, a wait-for cycle cannot form.

Q9. What does conservative 2PL cost?

It needs the complete lock set in advance. One unavailable lock delays the whole set, while locks acquired before use may reduce concurrency. Dynamic discovery, upgrades, ranges and phantoms make predeclaration harder. It is not universally better.

A split timeline contrasts a strict 2PL wait-for cycle with conservative 2PL preclaiming, where transactions run in sequence and finish with A plus B equal to 150.

5. Compare all four protocols and classify exact lock traces

Q10. Can you compare basic, strict, rigorous and conservative 2PL in one table?

Protocol

Acquisition rule

X lock before commit

S lock before commit

Deadlock

Cascading rollback

Basic 2PL

Acquire as needed in growing phase

May release

May release

Possible

Possible

Strict 2PL

Acquire as needed in growing phase

Hold to commit/abort

May release in shrinking phase

Possible

Prevented

Rigorous 2PL

Acquire as needed in growing phase

Hold to commit/abort

Hold to commit/abort

Possible

Prevented

Conservative 2PL

Preclaim complete set before execution

May release unless combined with strictness

May release unless combined with rigorousness

Prevented

Possible unless combined with strictness

All four use compatible shared and exclusive locks and are conflict-serializable under their 2PL rules. Conservative controls acquisition; strict and rigorous control retention. A system can combine them.

Classify each trace by its strongest label:

  • A, basic only: XL1(A), R1(A=100), W1(A=80), XL1(B), R1(B=50), W1(B=70), U1(A), U1(B), C1

  • B, strict but not rigorous: XL1(A), W1(A:100->80), SL1(B), R1(B=50), U1(B), C1/release X(A)

  • C, rigorous: SL1(A), R1(A=100), XL1(B), W1(B:50->70), C1/release both

  • D, conservative but neither strict nor rigorous: preclaim {X(A),S(B)}, W1(A:100->80), R1(B=50), U1(A), U1(B), C1

For broader practice, use DBMS Interview Questions for Freshers: Top 50 Answers.

6. Handle the traps: deadlocks, upgrades, recovery and protocol choice

Q11. Does strict 2PL prevent deadlocks, and does conservative 2PL prevent cascading rollback?

No to both. Suppose T1 and T2 hold SL1(A) and SL2(A), then both request X(A) upgrades. Each waits for the other's shared lock, so strict 2PL deadlocks before either X lock is granted. An upgrade is acquisition and belongs in the growing phase. Conservatively, each transaction would preclaim X(A), so only one receives it.

Conservative acquisition alone does not fix recovery. T1 may preclaim X(A) and X(B), write A = 80, then release X(A) before commit. T2 can preclaim {S(A)} and read 80. If T1 aborts and restores A = 100, T2 must also abort. Conservative acquisition plus strict retention prevents this dependency.

Q12. Which 2PL variation should you choose?

Choose by requirement. Basic 2PL is the serializability baseline. Strict excludes dirty reads, dirty writes and cascading rollback. Rigorous also keeps read locks to completion. Conservative suits a knowable lock set when deadlock avoidance justifies early acquisition. Real isolation must still cover lock granularity, range locking and implementation policy. No single label solves every concurrency problem.

7. Give the interview-ready short version and the next practice step

A 45-second answer is: basic 2PL separates acquisition from release and guarantees conflict serializability. Strict holds X locks to the end and prevents cascading rollback. Rigorous holds S and X locks to the end. Conservative obtains the whole lock set before execution and prevents deadlock. Strict can still deadlock, while conservative alone need not be strict.

For a whiteboard follow-up, reproduce the dirty-read trace, draw the two-node wait-for cycle, and classify A through D. Recall: basic = two phases; strict = X to end; rigorous = S and X to end; conservative = all before start. Use Database Management System for concept depth and the Interview & Resume Preparation Course for answer-delivery practice.