# Hosted App SAAS - Database Structure

**URL:** <https://www.ruby-forum.com/t/hosted-app-saas-database-structure/125557>\
**Category:** Rails\
**Created:** [January 10, 2008, 3:22am UTC](https://www.ruby-forum.com/t/hosted-app-saas-database-structure/125557 "2008-01-10T03:22:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![melvinram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@melvinram](https://www.ruby-forum.com/u/melvinram)\
**Post date:** [January 10, 2008, 3:22am UTC](https://www.ruby-forum.com/t/hosted-app-saas-database-structure/125557/1 "2008-01-10T03:22:44Z")

</div>

I am wondering… if you were going to create a hosted application for  
your clients… similar to a 37Signals app or [SalesForce.com](http://SalesForce.com), how  
would you structure the database and seperation of the accounts?

Would everyone’s data be in the same database (relying on the code to  
make sure the data does not overflow) or something else? Pointing me  
to any resources on the topic will be much appreciated.

~ mel

---

<div class="post-metadata">

**Author:** ![melvinram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@melvinram](https://www.ruby-forum.com/u/melvinram)\
**Post date:** [January 10, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/hosted-app-saas-database-structure/125557/2 "2008-01-10T14:20:14Z")

</div>

I am working on a SaaS solution as well. My design has one database  
and most tables in the database has an organization\_id to segregate  
data.

---

<div class="post-metadata">

**Author:** ![melvinram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@melvinram](https://www.ruby-forum.com/u/melvinram)\
**Post date:** [January 10, 2008, 3:29pm UTC](https://www.ruby-forum.com/t/hosted-app-saas-database-structure/125557/3 "2008-01-10T15:29:55Z")

</div>

Mel,

Think of it this way. What kind of a maintenance headache would you have  
if you created a new db for every customer?

Assuming you want lots of customers then you are probably going to want  
to minimise your operational overhead & store all data in a single db.

Look at the facebook API as guide, they probably have way more users  
than your app will, & you can see that they seem to keep all their user  
data in one db. Although you never know what is going on under the hood.

In its simplest form you probably want two tables, organisations & users  
& have the following relationships.

Organisation - has many users

User - belongs to organisation

rgds,

- matt.

Tickex - the search engine for concert, theatre, and sports tickets  
[http://www.tickex.com](http://www.tickex.com)

---

<div class="post-metadata">

**Author:** ![melvinram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@melvinram](https://www.ruby-forum.com/u/melvinram)\
**Post date:** [January 11, 2008, 6:54pm UTC](https://www.ruby-forum.com/t/hosted-app-saas-database-structure/125557/4 "2008-01-11T18:54:11Z")

</div>

Thanks for the feedback. I’m keep it in mind.

On Jan 10, 6:29 am, Matt S.1 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
