1

I am designing a CRM using Ruby on Rails. How do you think, do I need a separate database for every client company? Or should I use the same database for everyone?

4
  • I'm pretty sure you don't. Why would you? Commented Sep 6, 2012 at 18:38
  • Every company would have its data in a separate database. More secure and faster. Commented Sep 6, 2012 at 18:45
  • Is it faster when you need to do JOIN queries as well? Commented Sep 6, 2012 at 19:27
  • Why would you need to JOIN data from separate companies? Commented Sep 6, 2012 at 21:22

2 Answers 2

2

If they are separate companies or competing companies (for say a white label CRM) you'll most definitely want to run separate instances because then you can credibly claim total sandboxing. Otherwise, if you ever inadvertently wrote code that somehow allowed the data from one to display for the other, the game is over. Your customer will run for the hills and tell everyone about their terrible experience with your product.

I would even suggest you run separate instances of your app for each customer. Heroku provides a super simple way to deploy RoR apps so spinning up a new one whenever you add a new customer is a reasonable approach. Of course, if you want a more turnkey solution that allows people to just sign up for an account, you will have to have a single instance that enforces customer data sandboxing in code. Obviously it can be done, but the separation isn't done at the infrastructure level which is ultimately the safest way.

Best regards.

Sign up to request clarification or add additional context in comments.

2 Comments

Well said. Just want to add aside from the security standpoint and separation of data, this would also lead to smaller tables. When you get a lot of data, managing the indexes can be a bit heavy.
@MattLong Also, I can use the same database but different tables, right? I mean something like table [company_name]_records, which will be different for every company.
2

I do it with a single database, like this:

class Company < ActiveRecord::Base
  has_many :records

  def recent_records
   records.desc(:created_at)
  end
end

class Record < ActiveRecord::Base
  belongs_to :company
end 

Then, in the controller, I can write:

@records = @company.recent_records

And pass that down to the views.

Hope this helps.

2 Comments

This seems like a less secure, less scalable, and less performant solution than using separate DBs and App Instances for each customer.
Without numbers, I can't comment on that. This will work well for a large number of apps. The OP asked a general rails question, not a scaling question. Early optimization is the root of all evil, or so goes the saying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.