Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-Tenant Rails 3 App on Heroku using PostgreSQL

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 look awesome, but heroku doesn't handle large numbers of them well.

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?

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)?

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.

Really appreciate any help.

Update:

We ended up moving to a VPS (Rackspace Cloud) and implementing postgres's schemas. No regrets with this move as it runs much faster than it did on Heroku, and we have more control of the server.

like image 628
kmurph79 Avatar asked Nov 03 '22 21:11

kmurph79


1 Answers

Check out this gem which was written to do multi-tenancy with postgres http://railscraft.tumblr.com/post/21421806379/multi-tenanting-ruby-on-rails-applications-on-heroku

like image 71
Will Avatar answered Nov 09 '22 13:11

Will