Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Flask rate limiting solutions use Redis?

I want to rate limit my Flask API. I found 2 solutions.

  1. The Flask-Limiter extension.
  2. A snippet from the Flask website using Redis: http://flask.pocoo.org/snippets/70/

What is the significance of Redis when Flask-Limiter is able to rate limit the request on the basis of remote address without Redis?

like image 764
user3787291 Avatar asked Dec 07 '22 22:12

user3787291


1 Answers

Redis allows you to store the rate-limiting state in a persistent store.

This means you can:

  1. Restart your web server or web application and still have the rate-limitation work. You won't lose the records of the last requests made because of the working process being destroyed and a new one being created, instead.
  2. Use multiple web servers or web applications. This is because the rate-limitation state is stored in an external data store that also solves the issue of shared data synchronisation and data races. You can run as many web servers as you wish - the rate-limitation is shared among all of them.
  3. Look at the rate-limitation state. Redis offers easy CLI tools that allow you to look at the current active data in an ad-hoc manner, even MONITORing the incoming commands and requests.
  4. Let Redis manage TTL, LRU etc for rate-limitation algorithms. Redis supports this intrinsically.
like image 200
advance512 Avatar answered Dec 22 '22 18:12

advance512