title: Multi-Tenant Rails 3 App on Heroku using PostgreSQL
body: <p>I have a multi-tenant app on Heroku (multiple Accounts that know nothing about each other), and I'm unsure as how to best architect my database.  Postgres's schemas <a href="http://blog.jerodsanto.net/2011/07/building-multi-tenant-rails-apps-with-postgresql-schemas/" rel="nofollow">look awesome</a>, but heroku doesn't handle <a href="https://devcenter.heroku.com/articles/postgres-multiple-schema-support" rel="nofollow">large numbers of them well</a>.</p>
  
  <p>Now, my Rails app is mainly serving JSON, as most of the templates are rendering client-side (using Backbone.js).  So I'm considering moving to MongoDB because 1) each tenant could get one top level 'account' document, and everything could be nested below and 2) its storage format so closely resembles JSON.  We are still in beta, so it could be pulled off.  Are those valid reasons to use Mongo?  Is former even an intelligent way to use Mongo?</p>
  
  <p>If I were to stick with postgres, should everything belong_to the top level Account model (with indexes)?  If so, how would I handle joins?  Is it possible to perform mult-index joins (total postgres noob)?</p>
  
  <p>We have about 60k entries in one table so far, yet a single account may only have 200-1000, so I'm worried about joining on the entire table.</p>
  
  <p>Really appreciate any help.</p>
  
  <p>Update:</p>
  
  <p>We ended up moving to a VPS (Rackspace Cloud) and implementing postgres's schemas.  No regrets with this move as it runs <em>much</em> faster than it did on Heroku, and we have more control of the server.</p>