Open Changaco opened 7 years ago
https://github.com/alisaifee/limits seems to be the project most likely to accept a pull request for PostgreSQL support.
For the actual implementation I think a leaky/token bucket is okay, because with PostgreSQL we have transactions for atomic operations, and trying to avoid locks is pointless since every row update requires a lock.
However Cloudflare's algorithm is also worth considering. I'm not sure whether it would be more efficient than a bucket when implemented atop PostgreSQL.
I've tried to implement both approaches, the leaky bucket is simpler and doesn't seem less efficient.
In order to fix all throttling issues I've been reading up on rate-limiting. Here are the best articles I've found on the subject:
There are various modules on PyPI for rate-limiting and throttling, but there doesn't seem to be any that fits our technology stack. The only data store we have is our PostgreSQL DB, and that's enough to implement rate-limiting in a satisfactory way, we neither need nor want to set up Redis or Memcached.
So, what should be done: