Module 18 · Transactions and concurrency · Drill
Transactions and concurrency drill
Scenario prompts that check whether transactions and concurrency is usable under pressure. Answer out loud, then compare.
0 of 4 graded
Prompt 1
Test this schedule for conflict serializability and recoverability, showing your work: R1(A), W1(A), R2(A), R2(B), W2(B), C2, R1(B), W1(B), C1. If it is serializable, give the equivalent serial order; then say whether it is recoverable, cascadeless and strict.
Prompt 2
Two transactions run concurrently under strict 2PL. T1: UPDATE accounts SET bal = bal - 100 WHERE id = 1; UPDATE accounts SET bal = bal + 100 WHERE id = 2. T2 does the same transfer in the other direction, starting with id 2. Describe what happens step by step, how the database resolves it, and two ways the application can prevent it.
Prompt 3
An on-call scheduling app on PostgreSQL at REPEATABLE READ enforces 'at least one doctor on call per shift' in application code: count on-call doctors, and if more than one, allow going off call. Twice last month the shift ended up with nobody. Explain the anomaly precisely using MVCC, and give three fixes with their costs.
Prompt 4
A product team must choose a concurrency strategy for three operations: decrementing stock for a flash sale on one popular item, an admin editing a product description in a form for several minutes, and a nightly report that reads every order while checkout keeps running. Choose pessimistic locking, optimistic concurrency or MVCC snapshots for each and justify.