Dealing With Contention easy
In a database, what happens if Transaction A locks a row and Transaction B tries to modify the same row?
- A Transaction B crashes immediately.
- B Transaction B overwrites the data.
- C Transaction B waits (blocks) until Transaction A commits or rolls back (releasing the lock).
- D Transaction A is killed.
Answer: C. Transaction B waits (blocks) until Transaction A commits or rolls back (releasing the lock).
This is standard lock contention. If B waits too long, it triggers a 'Lock Timeout'.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- Why is 'Exponential Backoff' preferred over constant intervals for retries?
- What is the primary purpose of a Mutex (Mutual Exclusion) lock?
- Why does adding more threads sometimes *decrease* performance?
- In a Saga, if a Compensating Transaction (Undo) fails repeatedly due to contention, what is the last resort?
- A database restart causes thousands of application servers to instantly try to reconnect. This crashes the DB again. This is called:
- To save a system under extreme contention, you implement 'Load Shedding'. What is the most effective strategy?