Dealing With Contention hard
What is the key difference between a Semaphore and a Rate Limiter (Token Bucket)?
- A They are the same.
- B Semaphores are for disk, Rate Limiters are for network.
- C Semaphores limit *concurrency* (Parallelism: how many active *now*). Rate Limiters limit *throughput* (Rate: how many *per second*).
- D Rate limiters block threads.
Answer: C. Semaphores limit *concurrency* (Parallelism: how many active *now*). Rate Limiters limit *throughput* (Rate: how many *per second*).
If tasks take 0.1s, a Semaphore(10) allows 10 concurrent tasks (100 RPS). If tasks take 10s, it allows 1 RPS. A RateLimiter(100) allows 100 RPS regardless of duration.
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: