# Multiple customers/tenants - keeping the data separate - how?

**URL:** <https://www.ruby-forum.com/t/multiple-customers-tenants-keeping-the-data-separate-how/166216>\
**Category:** Rails\
**Created:** [April 22, 2009, 9:17pm UTC](https://www.ruby-forum.com/t/multiple-customers-tenants-keeping-the-data-separate-how/166216 "2009-04-22T21:17:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [April 22, 2009, 9:17pm UTC](https://www.ruby-forum.com/t/multiple-customers-tenants-keeping-the-data-separate-how/166216/1 "2009-04-22T21:17:44Z")

</div>

I have found this very good thread from 2006 about multi-tenant  
applications:  
[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/25bc6cd899318d9a/](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/25bc6cd899318d9a/)

I’m making my app available to multiple customers and right now my  
strategy is:

1. svn export code  
each customer has their own
2. rake setup:initialize client\_name  
which creates the databases and the database.yml file
3. rake db:migrate  
which creates all tables
4. rake setup:blank\_slate customer\_name  
which adds some necessary predefined data from a couple of YML files.

The problems with this setup are:

- the memory usage  
each tenant uses their own process and that takes a lot of memory  
which is ridiculous considering that they run the same code
- management and provisioning issues  
Updates are cumbersome and creating another app for a tenant is  
time consuming and not that automated. The whole process takes about 1  
minute. I I ddn’t check out the code it would take less than 20  
seconds.

I used before a hijack\_db metod as a before\_filter in  
ApplicationController that switched the database depending on the  
domain. I’m not sure about the performance or security of that hack.  
How do you guys manage multiiple tenants and multiple databases?

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [April 23, 2009, 5:22am UTC](https://www.ruby-forum.com/t/multiple-customers-tenants-keeping-the-data-separate-how/166216/2 "2009-04-23T05:22:31Z")

</div>

On Wed, Apr 22, 2009 at 9:16 PM, Constantin G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> which creates the databases and the database.yml file  
> Updates are cumbersome and creating another app for a tenant is  
> time consuming and not that automated. The whole process takes about 1  
> minute. I I ddn’t check out the code it would take less than 20  
> seconds.
> 
> I used before a hijack\_db metod as a before\_filter in  
> ApplicationController that switched the database depending on the  
> domain. I’m not sure about the performance or security of that hack.  
> How do you guys manage multiiple tenants and multiple databases?

This is a great talk/video on multi-tenant application development  
from Acts As Conference 2009  
[http://aac2009.confreaks.com/06-feb-2009-14-30-writing-multi-tenant-applications-in-rails-guy-naor.html](http://aac2009.confreaks.com/06-feb-2009-14-30-writing-multi-tenant-applications-in-rails-guy-naor.html)

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)  
[http://www.linkedin.com/in/andrewtimberlake](http://www.linkedin.com/in/andrewtimberlake)

“I have never let my schooling interfere with my education” - Mark Twain
