Databases · Senior · Question 9 of 75
What is write skew?
-- Rule: at least one doctor must be on call.
-- T1 and T2 both see 2 doctors on call, each takes one off.
UPDATE doctors SET on_call = false WHERE id = 1; -- T1
UPDATE doctors SET on_call = false WHERE id = 2; -- T2- 1A write that's slower than a read
- 2A replica receiving writes out of order
- ✓Correct answer: Two transactions read overlapping data, then update different rows, together breaking a rule neither would break alone
Explanation
Repeatable Read (snapshot isolation) allows it. Serializable isolation, explicit locks (FOR UPDATE on the rows checked) or a constraint prevent it.