I'm building a Rails 3 app for deployment on Heroku, and I'm wondering if there are any recommendations on how to handle multi-tenancy in my models. Half a year ago, there was a related question (#3776593) posted on here, but it didn't get many answers. I've also watched Guy Naor's presentation on writing multi-tenant applications with Rails, but it seems like 2 of the 3 proposed solutions wouldn't work on Heroku. I'd link to these, but new Stackoverflow users are limited to 2 hyperlinks.
I've also come across the following tools:
Just wondering if you have experience with either the multitenant gem or the simple-rails-multi-tenancy gem. Seems like the most straightforward solution would be to simply put a belongs_to on all my models that need to be under an Account, but I'd really like to know what you're using in the real world!
The approaches range from "share nothing", which usually means one database per tenant, to "share everything", which usually means each table contains rows from many tenants. The spectrum (below) can be broken down by degree of isolation, by cost (cost per tenant, that is), and by ease of disaster recovery.
All those are platform-specific to some degree. "One database per tenant" has the highest isolation when the dbms prohibits queries from accessing more than one database. But some platforms allow querying across multiple databases.
MSDN has a decent article that hits the high points: Multi-Tenant Data Architecture.
But if you're limited to Heroku, you'll have to pick an option that Heroku supports. I don't know what those options might be, but I do know that you're better off not using SQLite in development. Heroku deployments are going to run on PostgreSQL; you need to develop against PostgreSQL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With