The Burst Handler
Difficulty: MEDIUMID: rate-limit-token-bucket-002
The Scenario
You are scraping a strict API. It allows bursts (up to 10 requests instantly) but enforces a long-term rate of 1 request/second.
The Problem
Your current implementation uses a StrictLimiter. It enforces a rigid 1-second gap between every request (Leaky Bucket style).
While this is "safe" (you won't get banned), it is too slow. It fails to utilize the API's "Burst" allowance. If you have 10 requests to make, you should be able to make them instantly because you haven't used your allowance yet. The StrictLimiter forces you to wait 10 seconds.
The Goal
Refactor the StrictLimiter class into a Token Bucket algorithm.
- Bank Tokens: Accumulate tokens when idle (up to capacity 10).
- Burst: Spend tokens instantly to make requests without waiting.
- Throttle: Only wait when the bucket is empty.
solution.py
Loading...
SYSTEM_LOGS
// Waiting for execution trigger...