Throttling outbound API calls generated by a Rails app Throttling outbound API calls generated by a Rails app ruby-on-rails ruby-on-rails

Throttling outbound API calls generated by a Rails app


Try using nginx as a proxy: http://codetunes.com/2011/07/26/outbound-api-rate-limits-the-nginx-way .

If you're on heroku, then consider using the Slow Web gem.


There is now a gem for that: throttle-queue. It takes a code block and makes sure it gets executed only x times per second. This is an example taken from the Readme, that would fetch only three files per second:

require 'throttle-queue'q = ThrottleQueue.new 3files.each {|file|    q.background(file) {        fetch file    }}


The reason nobody talk about outbound throttling is that it's usually pretty trivial, since you control it. Controlling bandwidth can be a bit harder, but controlling number of request ?

ri Kernel#sleep

So, if you're allowed 10 api calls per min you just sleep(6) after each call