datacurve-ai / codeforces-discord-bot

A Discord bot middleman for interacting with Codeforces
0 stars 4 forks source link

Debug: Rate Limiting #2

Closed lsha0730 closed 1 month ago

lsha0730 commented 1 month ago

The Codeforces API may be requested at most 1 time per two seconds. If the users of the bot exceed this limit, the bot will receive a 429 Too Many Requests response. To prevent this, we need to implement a rate limiting mechanism to control the number of requests made to the API.

  1. Timing Tracking: Implement a system to track the timing of each API request made by the bot.
  2. Rate Limiting Logic: Develop logic to enforce a minimum delay of two seconds between consecutive API requests.
  3. Throttling Mechanism: Implement a queue to hold API requests when the rate limit is reached, processing them in a controlled manner.
  4. Error Handling: Handle Too Many Requests responses by retrying the request after an appropriate delay.
lsha0730 commented 1 month ago

Closing because the best solution to the problem was determined too simple to demonstrate complexity