Dealing With Contention medium
If you use a Semaphore with 5 permits to protect a database connection pool, what happens when the 6th thread tries to acquire?
- A It crashes.
- B It blocks (waits) until a permit is released.
- C It creates a new connection.
- D It steals a permit.
Answer: B. It blocks (waits) until a permit is released.
This provides rigid concurrency control, ensuring the DB is never overloaded by more than 5 in-flight queries.
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: