I found an alternative to the limits library: arate-limit. It implements a sliding window algorithm backed by Redis, which is exactly what I needed for accurate rate limiting in a distributed environment.
In addition, I came across a small library called limited_aiogram, which provides built-in rate limiting for Telegram bots using aiogram
. It works better than my initial implementation. However, it only supports in-memory storage. That said, it should be fairly straightforward to adapt it to use Redis by integrating arate-limit
as a backend.
As for why my own implementation isn't working correctly - I still don't know the exact reason. It's possible that the problem is in my code, but it may also be related to the limitations or behavior of the libraries I used.
If you encounter a similar problem, use arate-limit
.
Please respond if you know that I used limits incorrectly for the limit.