Log inBook a Demo
BuildMidBackendAuto-graded

Fix a rate limiter that leaks across windows

Callers can get up to twice their limit by bursting either side of a window boundary; make the limit hold over any rolling window.SlidingWindowLimiter should allow each caller at most limit requests in any window_seconds. It behaves under normal traffic, but in production a caller can send its full allowance just before a window boundary and again just after, getting twice the limit within one window. Fix it so the limit holds over every rolling window. Read time only through the injected now clock, because that's how it gets tested.
35 min
python

You're done when

  • Requests up to the limit are allowed and the next one is blocked.
  • Old requests free up their slot one by one as each ages out of the window.
  • A caller can't get twice the limit by bursting on both sides of a window boundary.
  • Each caller has its own budget, so one caller's traffic never uses up another's.
  • A caller that has been idle for longer than the window gets its full budget back.

What it measures

Data structures and algorithmsKeeping state that gives an exact count of recent requests for any limit and window size.
Test-driven developmentWhether your tests drive the clock by hand and cover window edges as well as steady traffic.
Edge-case judgementSpotting that a limiter can look right under normal load and still let through double at a boundary.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

35 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo