Dealing With Contention hard
Transaction T1 locks Row A on Shard 1 and wants Row B on Shard 2. Transaction T2 locks Row B on Shard 2 and wants Row A on Shard 1. How is this Distributed Deadlock typically detected?
- A It cannot be detected.
- B Timeouts. Since building a global dependency graph is expensive and slow, most distributed systems simply kill transactions that wait longer than X seconds.
- C By a central coordinator.
- D By checking CPU usage.
Answer: B. Timeouts. Since building a global dependency graph is expensive and slow, most distributed systems simply kill transactions that wait longer than X seconds.
Graph-based detection is possible but rarely worth the complexity/overhead in high-throughput distributed stores.
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?
- In a database, what happens if Transaction A locks a row and Transaction B tries to modify the same row?
- A database restart causes thousands of application servers to instantly try to reconnect. This crashes the DB again. This is called: