BuildMidBackendAuto-graded
Fix a rate limiter that leaks across windows
A timing flaw lets usage limits be exceeded at the seam between periods, and the fix has to be proved.A rate limiter should cap each caller at a fixed number of requests per window. This one passes the naive tests and leaks in production: a caller fires its full allowance just before a window boundary and the full allowance again just after, getting double the limit inside a single rolling window. It is a fixed-window counter pretending to be a sliding one. Make it a true sliding window, counting only what falls inside the trailing interval at each instant.35 min
python
You're done when
- Requests up to the limit are allowed and further ones are blocked.
- The window genuinely slides — entries expire individually as they age out, rather than all at once.
- The boundary burst is gone: a caller cannot get double the limit by straddling a window edge.
- Callers are isolated from each other — one caller's traffic does not consume another's allowance.
- A key that has been idle gets its full fresh budget.
What it measures
Data structures and algorithmsMaintaining a time-ordered window with individual expiry rather than a periodically reset counter.
Test-driven developmentWriting the boundary-straddling test that exposes the leak, which the naive test suite never does.
Seeing past passing testsRecognising that a limiter passing its tests can still be twice as permissive as advertised at exactly the moment it matters.
Your environment
Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards
Start this lab
35 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo