Best practices for multitenant application?

Are there any best practices for designing multitenant applications
using rails? Would I want to run 10 instances of the same application,
or one instance of an application that can handle 10 tenants?

What if I was making a forum, for example, and people could come and
sign up and create their own forums. Are there any good ways for
segregating all the topics in one forum from all the topics in
another? All the users in one forum from all users in another?

I realize this question is rather vague, and the real reason I’m
asking is that people are saying good things about using RESTful
resources and things in rails applications, but it doesn’t seem like
it would handle multitenant applications very well. I would certainly
want a different posts/get route for each tenant, for example.

Philip B. wrote:

Are there any best practices for designing multitenant applications
using rails? Would I want to run 10 instances of the same application,
or one instance of an application that can handle 10 tenants?

What if I was making a forum, for example, and people could come and
sign up and create their own forums. Are there any good ways for
segregating all the topics in one forum from all the topics in
another? All the users in one forum from all users in another?

I realize this question is rather vague, and the real reason I’m
asking is that people are saying good things about using RESTful
resources and things in rails applications, but it doesn’t seem like
it would handle multitenant applications very well. I would certainly
want a different posts/get route for each tenant, for example.

No problems.

Free your mind and abstract one level higher.

class Forum

belongs_to :user

has_many :topics

end

class Topic

has_many :threads

end

map.resources :forums do |forums|
forums.resources :topics do |topics|
topics.resources :threads

end
end
end

Cheers.

Typically people building multi-tenant applications will scope the
data based on an Account model (or something similar) which is loaded
at request time by fetching a record based on the request host. That
is, each account has its own subdomain, so you know which data to load
based on that. In your case, a Forum could have a domain field, and
you have a before filter that loads the forum based on request.host,
and then displays posts scoped to that forum: e.g.
@forum.posts.find(:all) in the index action.

It just so happens that I have code that implements this very model,
along with all the code needed to implement recurring billing, should
you be building something you want people to pay you to use. :slight_smile: Check
it out at http://railskits.com/saas/ – it’s not free, but it would
come in very handy for you.


Benjamin C.
http://catchthebest.com/ - Team-powered recruiting
http://www.bencurtis.com/ - Personal blog

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs