Concurrency & payments · Bug Squash (Java)
The limiter that admits one too many
A fixed-window rate limiter in Java allows 100 requests per key per minute, and request 101 gets through. Where is the bug?
Bug Squash · Java 21 · FixedWindowLimiter.javaIllustrative scenario, not a real incident
Request 101 in one minute was accepted for a key limited to 100
A payments API allows each API key at most 100 requests per minute. Request 101 in the same minute must get a 429.
A partner's own log shows 101 accepted calls inside one window, and 103 during a burst from several of its workers. A test that reproduces the first case is below. No code runs in your browser: read it as you would in a review.
What the dashboards and logs show
- Expected
- 100 admitted, call 101 rejected
- Actual
- 101 admitted, call 102 rejected
- Clock in the test
- fixed, so all 101 calls fall in one window
- During a burst
- 103 admitted in one window, seen once in the partner's log
Find the bug · scored under "Hypothesis before change"
Tap the faulty lines
The test below fails. Mark up to 3 lines you would change, then check them. There are 2. A wrong mark costs half a line.
FixedWindowLimiterTest > requestAfterTheLimitIsRejected() FAILED
org.opentest4j.AssertionFailedError:
101 calls for key-A inside one window, limit 100
admitted expected: <100> but was: <101>
1 test completed, 1 failedNo line marked yet
Your rubric score, the model answer, the follow-up questions and the related lessons appear once you have answered the last step.