lkartono
lkartono

Reputation: 2393

Rails Database design and multiple subdomain

I'm actually starting a new project and I need some advice regarding the database design. Let me explain a little bit first.

I'm gonna build this application on the top of Ruby On Rails. Each new user gonna have his own url such as username.domain.com.

So far so good, but what about the database? Should I use just one single database and handle everything from there using the user session information to retreive datas, or should I create a new database for every users?

Some poeple suggested me to use a prefix on my tables' name such as WP or Drupal does to handle multiple website but I really found that solution DIRTY and not maintainable on the long run since I need to duplicate all my tables for every users. What if I have 10.000 users and 100 common tables? Messy no?

Every ideas are welcome.

Thanks a lot

Upvotes: 1

Views: 303

Answers (2)

Mark Swardstrom
Mark Swardstrom

Reputation: 18080

Ryan Bates did a Railscast on multitenancy - it's a 'pro' episode and requires a subscription, but has great information on this topic.

http://railscasts.com/episodes/388-multitenancy-with-scopes

Upvotes: 1

Peter Wooster
Peter Wooster

Reputation: 6089

It really depends on the use cases. Are these users separate and you are just providing a hosting service? If so you might want separate databases. Or are they related, as in a social network and share a lot of functionality in common and would have many joins between their tables. In that case you probably want a single database.

Upvotes: 1

Related Questions