Dealing With Contention easy
What is a Race Condition?
- A When two threads compete to finish a task first to save CPU.
- B When the system runs out of memory.
- C A situation where the system's behavior depends on the uncontrolled scheduling order of threads/processes, often leading to incorrect data (e.g., lost updates).
- D When the network is too slow.
Answer: C. A situation where the system's behavior depends on the uncontrolled scheduling order of threads/processes, often leading to incorrect data (e.g., lost updates).
If Thread A reads X=5, pauses, Thread B reads X=5, writes X=6, then Thread A writes X=6, one update is lost. The outcome depends on who 'wins the race'.
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: