# Multiple sites using one data source

**URL:** <https://www.ruby-forum.com/t/multiple-sites-using-one-data-source/102111>\
**Category:** Rails\
**Created:** [August 10, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/multiple-sites-using-one-data-source/102111 "2006-08-10T22:02:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@chero](https://www.ruby-forum.com/u/chero)\
**Post date:** [August 10, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/multiple-sites-using-one-data-source/102111/1 "2006-08-10T22:02:34Z")

</div>

Hi,

Just wondering if anyone has any suggestions as to the best way to  
provide access to the same data source for the (possible) creation of  
multiple web sites. I figure my options are:

- Direct database access over tcp
- ActionWebService
- Wait for ActionResource

I’ve done up some work with ActionWebService already, but I don’t think  
it’s going to work because it is so slow for me. All I’m doing is  
displaying a list of 12 product categories and it takes way too long.  
This is running under development mode and fastcgi.

Direct database access would be the fastest in terms of performance I  
imagine?

Are web services not really targeted for solving this sort of problem  
(creating multiple web sites using one data source)?

---

<div class="post-metadata">

**Author:** ![chero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@chero](https://www.ruby-forum.com/u/chero)\
**Post date:** [August 15, 2006, 2:15pm UTC](https://www.ruby-forum.com/t/multiple-sites-using-one-data-source/102111/2 "2006-08-15T14:15:38Z")

</div>

On 8/10/06, James E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Just wondering if anyone has any suggestions as to the best way to  
> provide access to the same data source for the (possible) creation of  
> multiple web sites.

Direct DB access works well if all your app servers can see all the  
involved databases. Where I previously worked we ran three sites,  
each with their own database as well as a shared user database. It  
worked out very well.

In doing that, though, you get a lot of speed but tie your apps pretty  
tightly together. Especially the parts sharing the same database.  
With a web service, you can of course keep the interface fairly  
consistent and are free to whimsically change implementation details.  
I think the answer is more of a “whatever suits your needs” type deal.

That said, there’s some code at this link for connecting a model to an  
external database:

[http://www.pjhyett.com/articles/2006/01/25/rails-interacting-with-an-external-database](http://www.pjhyett.com/articles/2006/01/25/rails-interacting-with-an-external-database)

Comment #3 is really concise. That might suit your needs.

---

<div class="post-metadata">

**Author:** ![chero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@chero](https://www.ruby-forum.com/u/chero)\
**Post date:** [August 15, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/multiple-sites-using-one-data-source/102111/3 "2006-08-15T17:47:05Z")

</div>

Chris W. wrote:

> On 8/10/06, James E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Just wondering if anyone has any suggestions as to the best way to  
> > provide access to the same data source for the (possible) creation of  
> > multiple web sites.
> 
> Direct DB access works well if all your app servers can see all the  
> involved databases. Where I previously worked we ran three sites,  
> each with their own database as well as a shared user database. It  
> worked out very well.
> 
> In doing that, though, you get a lot of speed but tie your apps pretty  
> tightly together. Especially the parts sharing the same database.  
> With a web service, you can of course keep the interface fairly  
> consistent and are free to whimsically change implementation details.  
> I think the answer is more of a “whatever suits your needs” type deal.
> 
> That said, there’s some code at this link for connecting a model to an  
> external database:
> 
> [http://www.pjhyett.com/articles/2006/01/25/rails-interacting-with-an-external-database](http://www.pjhyett.com/articles/2006/01/25/rails-interacting-with-an-external-database)
> 
> Comment #3 is really concise. That might suit your needs.

Thanks! I think that may be exactly what I’ve been looking for.  
Developing a web service would be cool, but it may be overkill, and  
never get utilized in this case. It’s tempting though, to take the  
basic data that I’m finding I need to share, and spawn off it’s own  
internet service.

---

<div class="post-metadata">

**Author:** ![chero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@chero](https://www.ruby-forum.com/u/chero)\
**Post date:** [August 15, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/multiple-sites-using-one-data-source/102111/4 "2006-08-15T14:16:14Z")

</div>

You don’t have to wait for ActiveResourec… simply\_restful is a plugin  
right now that you can use. That’s what I’d do if I was in your  
situation.

Use WEBrick or Mongrel for development mode. There are known memory  
leaks  
using fastcgi in Development mode (production mode is fine… leaks are  
due  
to the constant reloading of models and controllers in dev mode).

Your app will run considerably faster in production mode btw.

---

<div class="post-metadata">

**Author:** ![chero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@chero](https://www.ruby-forum.com/u/chero)\
**Post date:** [August 15, 2006, 5:49pm UTC](https://www.ruby-forum.com/t/multiple-sites-using-one-data-source/102111/5 "2006-08-15T17:49:59Z")

</div>

Brian H. wrote:

> You don’t have to wait for ActiveResourec… simply\_restful is a plugin  
> right now that you can use. That’s what I’d do if I was in your  
> situation.
> 
> Use WEBrick or Mongrel for development mode. There are known memory  
> leaks  
> using fastcgi in Development mode (production mode is fine… leaks are  
> due  
> to the constant reloading of models and controllers in dev mode).
> 
> Your app will run considerably faster in production mode btw.

Isn’t ActiveResource different from the simply\_restful plugin though?  
Correct me if I’m wrong, but ActiveResource is for developing XML based  
web services, and simply\_restful is just for making controller actions  
more RESTful?

---

<div class="post-metadata">

**Author:** ![chero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@chero](https://www.ruby-forum.com/u/chero)\
**Post date:** [August 15, 2006, 8:51pm UTC](https://www.ruby-forum.com/t/multiple-sites-using-one-data-source/102111/6 "2006-08-15T20:51:31Z")

</div>

Sorry for the confusion…  
But what I meant was that you could use the SimplyRestful stuff right  
now to  
make your applications talk. App 1 calls app2’s controllers using  
restful  
actions.

I’m doing some similar stuff right now that way but I’m actually not  
using  
SimplyRestful (Refactoring soon though) and it’s working so far. (proof  
of  
concept though)

---

<div class="post-metadata">

**Author:** ![chero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@chero](https://www.ruby-forum.com/u/chero)\
**Post date:** [August 15, 2006, 10:00pm UTC](https://www.ruby-forum.com/t/multiple-sites-using-one-data-source/102111/7 "2006-08-15T22:00:59Z")

</div>

Brian H. wrote:

> Sorry for the confusion…  
> But what I meant was that you could use the SimplyRestful stuff right  
> now to  
> make your applications talk. App 1 calls app2’s controllers using  
> restful  
> actions.
> 
> I’m doing some similar stuff right now that way but I’m actually not  
> using  
> SimplyRestful (Refactoring soon though) and it’s working so far. (proof  
> of  
> concept though)

How do have app2 call app1’s controller actions? Do you just use  
render\_to\_string or something, and then have app1 respond with xml?

It appears I could probably start using ActiveResource now. It may have  
all the functionality I need (basically readonly right now).
