# About: multi database performance on Substruct

**URL:** <https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872>\
**Category:** Rails\
**Created:** [September 17, 2008, 9:47pm UTC](https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872 "2008-09-17T21:47:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mekdigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/919ad9/32.png) [@mekdigital](https://www.ruby-forum.com/u/mekdigital)\
**Post date:** [September 17, 2008, 9:47pm UTC](https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872/1 "2008-09-17T21:47:06Z")

</div>

Hello,  
I forked the sweet Substruct and applied Advanced Recipe 83: I associate  
a  
different shop (separate database) to each ‘installation’ according to  
the  
subdomain the application is accessed from. Do you think it makes sense?  
Basically AR queries main database once to fetch ‘installation’ object  
and  
connects to installation.database if the subdomain is configured or  
loads  
the demo database/shop instead. It seems a good idea (to me) to keep  
every  
(admin) account clearly separated and it’s by far easier not to  
completely  
re-write Substruct logic to manage more than one admin. Passenger on  
dreamhost.

–  
Emanuele T.  
+1 (619) 549 3230  
4955 Narragansett Ave Apt #9  
San Diego Ca 92107-3157

> **[MekDigital.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=mekdigital.com)**
>
> Join thousands of people who own a premium domain. Affordable financing available.

---

<div class="post-metadata">

**Author:** ![mekdigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/919ad9/32.png) [@mekdigital](https://www.ruby-forum.com/u/mekdigital)\
**Post date:** [September 18, 2008, 6:38am UTC](https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872/2 "2008-09-18T06:38:30Z")

</div>

> the demo database/shop instead. It seems a good idea (to me) to keep  
> every  
> (admin) account clearly separated and it’s by far easier not to  
> completely  
> re-write Substruct logic to manage more than one admin. Passenger on  
> dreamhost.

Sounds good to me if you can manage it 🙂  
-=R

---

<div class="post-metadata">

**Author:** ![mekdigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/919ad9/32.png) [@mekdigital](https://www.ruby-forum.com/u/mekdigital)\
**Post date:** [September 18, 2008, 7:17am UTC](https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872/3 "2008-09-18T07:17:37Z")

</div>

So where’s the fork?

* * *

## seth - subimage llc

## [http://sublog.subimage.com](http://sublog.subimage.com)

## Cashboard - Estimates, invoices, and time tracking software - for free! [http://www.getcashboard.com](http://www.getcashboard.com)

Substruct - Open source RoR e-commerce software.  
[http://code.google.com/p/substruct/](http://code.google.com/p/substruct/)

---

<div class="post-metadata">

**Author:** ![mekdigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/919ad9/32.png) [@mekdigital](https://www.ruby-forum.com/u/mekdigital)\
**Post date:** [September 18, 2008, 7:38am UTC](https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872/4 "2008-09-18T07:38:01Z")

</div>

Why you need to go for the isolated database for each tenant (shop)?  
What are all the advantages and disadvantages of this? How you will  
achieve this technically in ROR application? How the active records will  
know what connection to use?

Just curious to know since we are also analyzing deep in what are all  
the pros and cons in using the isolated database for each tenant. We  
have some thought on this design. Just curious to know what others are  
thinking on this.

---

<div class="post-metadata">

**Author:** ![mekdigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/919ad9/32.png) [@mekdigital](https://www.ruby-forum.com/u/mekdigital)\
**Post date:** [September 19, 2008, 10:17am UTC](https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872/5 "2008-09-19T10:17:47Z")

</div>

On Wed, Sep 17, 2008 at 10:38 PM, Ayyanar Aswathaman \<  
removed\_email\_address@domain.invalid\> wrote:

> Why you need to go for the isolated database for each tenant (shop)?

I’m trying to add multi admin/shop support to the application and, seen  
the  
original database structure, it seems easier just to use one database  
for  
each shop.

> What are all the advantages and disadvantages of this?

This is what I’m trying to find out. So far, so good but I didn’t see  
any  
other application dealing with multiple database and when you’re the  
only  
one you’re usually on the wrong path!

> how you will achieve this technically in ROR application? How the active  
> records will know what connection to use?

This is quite easy: using subdomains for shops I just ask AcriveRecord  
to  
connect to the ‘current’ database, basically every database is a copy of  
the  
original one, I wrote some  
new rake code (and found out later that I’m not allowed to script-create  
database, but this is another story!)  
There is only one model, ‘Installation’ that always connects to the main  
database and it’s used to switch between shops. I’m trying to find out  
if  
shop switch can create a mess, but  
everything is okay by far…

@installation = Installation.for(request.host, request.subdomains)  
…  
ActiveRecord::Base.establish\_connection(:adapter =\> “mysql”,  
:host =\> “localhost”,  
:username =\> “root”,  
:password =\> “”,  
:database =\> @installation.database)  
…

see [http://mek.venicebuy.eu/](http://mek.venicebuy.eu/) and [http://usul.venicebuy.eu/](http://usul.venicebuy.eu/) are running  
online

> Just curious to know since we are also analyzing deep in what are all  
> the pros and cons in using the isolated database for each tenant. We  
> have some thought on this design. Just curious to know what others are  
> thinking on this.

I wish I could see this application with heavy load and we could  
understand!  
🙂

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Emanuele T.  
+1 (619) 549 3230  
4955 Narragansett Ave Apt #9  
San Diego Ca 92107-3157

> **[MekDigital.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=mekdigital.com)**
>
> Join thousands of people who own a premium domain. Affordable financing available.

---

<div class="post-metadata">

**Author:** ![mekdigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/919ad9/32.png) [@mekdigital](https://www.ruby-forum.com/u/mekdigital)\
**Post date:** [September 23, 2008, 8:38am UTC](https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872/6 "2008-09-23T08:38:11Z")

</div>

How you do the authentication and authorization in your multi-tenant  
application? Are you using any authentication and authorization  
plug-ins?

---

<div class="post-metadata">

**Author:** ![mekdigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/919ad9/32.png) [@mekdigital](https://www.ruby-forum.com/u/mekdigital)\
**Post date:** [September 23, 2008, 8:32am UTC](https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872/7 "2008-09-23T08:32:25Z")

</div>

Thanks Emanuele.

---

<div class="post-metadata">

**Author:** ![mekdigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/919ad9/32.png) [@mekdigital](https://www.ruby-forum.com/u/mekdigital)\
**Post date:** [September 29, 2008, 7:08am UTC](https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872/8 "2008-09-29T07:08:32Z")

</div>

I’m using the normal Substruct authorization methods: each subdomain not  
only load the appropriate database (and every admin has his own password  
for  
his db), but alsocreate a different session and things stay clean and  
work  
(so far)!

On Mon, Sep 22, 2008 at 11:38 PM, Ayyanar Aswathaman \<  
removed\_email\_address@domain.invalid\> wrote:

> ## How you do the authentication and authorization in your multi-tenant application? Are you using any authentication and authorization plug-ins?
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Emanuele T.  
+1 (619) 549 3230  
4955 Narragansett Ave Apt #9  
San Diego Ca 92107-3157

> **[MekDigital.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=mekdigital.com)**
>
> Join thousands of people who own a premium domain. Affordable financing available.

---

<div class="post-metadata">

**Author:** ![mekdigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/919ad9/32.png) [@mekdigital](https://www.ruby-forum.com/u/mekdigital)\
**Post date:** [October 15, 2008, 6:23pm UTC](https://www.ruby-forum.com/t/about-multi-database-performance-on-substruct/148872/9 "2008-10-15T18:23:02Z")

</div>

> I’m trying to add multi admin/shop support to the application and, seen  
> the  
> original database structure, it seems easier just to use one database  
> for  
> each shop.

Also checkout [http://tomayko.com/writings/rails-multiple-connections](http://tomayko.com/writings/rails-multiple-connections) and  
Dr. nic’s magic multi connections 🙂  
-=R
