We added some geocoding to one of our Heroku apps recently, and it seemed to be working fine during development and testing. However, once in production our automatic app health monitoring detected sporatic failures (the worst kind!) in the geocoding process. The logged showed the Google api would suddenly stop returning geocoding results due to rate limiting.

We were aware of Google’s limits on the geocode API, but our app uses geocoding infrequently so we were surprised to see the limits kick in.

In retrospect, the reason was obvious – Google meters usage by IP address, our app is hosted at Heroku, and the zillons of Heroku apps all share a very small number of IP addresses. So even if our usage was trivially small, other Heroku apps were chewing up the geocoding allotment for each Heroku IP.

Fortunately, the folks at www.quotaguard.com offer an add-on (currently in beta) to handle the situation… the ‘test’ plan provides a proxy service good for up to 2500 Google maps API requests/day, so your Heroku app’s requests to the geocoding api come from an IP supplied by Quotaguard (instead of the default Heoku IPs).

Enabling it was a snap:

  1. Add the quotaguard:test addon to your app

heroku addons:add quotaguard:PLAN (quotaguard:test for example)

This will add a QUOTAGUARD_URL setting to your Heroku environment, which you can see via heroku config

  1. If you’re using the geocoder gem, add this to config/initializers/geocoder.rb

Geocoder.configure( :http_proxy => ENV['QUOTAGUARD_URL'].gsub(/^http:\/\//, ''), :timeout => 5 )