Dealing With Contention easy
How does a Semaphore differ from a Mutex?
- A Semaphores are for networking only.
- B A Mutex allows only 1 thread (Key). A Semaphore allows N threads (Tickets) to access a resource concurrently (e.g., limiting to 5 connections).
- C Mutexes are faster.
- D Semaphores are obsolete.
Answer: B. A Mutex allows only 1 thread (Key). A Semaphore allows N threads (Tickets) to access a resource concurrently (e.g., limiting to 5 connections).
A Mutex is binary (Locked/Unlocked). A Semaphore is a counter (Counting Semaphore) used for rate limiting or pool management.
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: