NEW TICKET#38 · Public API
Sliding-window rate limit
Hannah Cole · Senior Engineer
Opened today
“Someone's script is hammering our invoices API. We'll allow at most limit requests in any windowMs milliseconds, per API key. Use a sliding window: when a request arrives at time t, count the allowed requests from the last windowMs (later than t − windowMs). Under the limit, it's allowed; otherwise it's refused. A refused request doesn't count against later ones, or a client who keeps retrying would be locked out for good. Can you write allowed?”
YOUR PLAN
- 1Watch an example2 min
- 2Warm-up 11 min
- 3Warm-up 21 min
- 4Fix the ticket26 min
BY THE END YOU CAN
- Keep a list of what has been let through
- Count only the recent items with a cutoff
- See why fixed buckets let bursts through at the edges