I would recommend filtering users or IP. Basically, keep track of each request, and if someone exceeds a certain number, do not allow further requests.
You can implement it yourself, saving the track of the number of requests of each user or IP address, or you can use some already built code, for example, Rack attack .
source
share