Beach Volleyball Scores Problem¶
You recently developed a REST API that lets people fetch scores and details about beach volleyball games. Unfortunately, some people are abusing the API, making hundreds of requests per second !
In order to protect your servers, implement a sliding window API rate limiter that works like this..
- Each request to your API has an associated API key.
- Each API key is allowed to make up to 5 requests in any 10-second window.
Exclude denied requests from each key's quota. In other words, if a key makes a request every second for 60 seconds, 30 of its requests should be allowed (5 allowed, then 5 denied, then 5 allowed, then 5 denied, ...).
def allow_request(api_key: str): """ Check if this api key is allowed to make a request right now. :return: True or False """ pass