<p>I am developing a website that will manage data for multiple entities.  No data is shared between entities, but they may be owned by the same customer.  A customer may want to manage all their entities from a single "dashboard".  So should I have one database for everything, or keep the data seperated into individual databases?
Is there a best-practice?  What are the positives/negatives for having a:</p>

<ul>
<li>database for the entire site (entity
has a "customerID", data has
"entityID")</li>
<li>database for each
customer (data has "entityID")</li>
<li>database for each entity (relation of
database to customer is outside of
database)</li>
</ul>

<p>Multiple databases seems like it would have better performance (fewer rows and joins) but may eventually become a maintenance nightmare.</p>

[{'answer_id': 20323, 'author': 'Lasse V. Karlsen', 'author_id': 267, 'author_profile': 'https://Stackoverflow.com/users/267', 'pm_score': 1, 'selected': False, 'text': '<p>What about backup and restore? Could you experience a customer wanting to restore a backup for one of their entities?</p>\n'}, {'answer_id': 20330, 'author': 'Vaibhav', 'author_id': 380, 'author_profile': 'https://Stackoverflow.com/users/380', 'pm_score': 1, 'selected': False, 'text': '<p>This is a fairly normal scenario in multi-tenant SAAS applications. Both approaches have their pros and cons. Search on best practices for multi-tenant SAAS (software as a service) and you will find tons of stuff to ponder upon.</p>\n'}, {'answer_id': 20340, 'author': 'Vaibhav', 'author_id': 380, 'author_profile': 'https://Stackoverflow.com/users/380', 'pm_score': 0, 'selected': False, 'text': "<p>One good argument for keeping them in separate databases is that its easier to scale (you can simply have multiple installations of the server, with the client databases distributed across the servers).</p>\n\n<p>Another argument is that once you are logged in, you don't need to add an extra where check (for client ID) in each of your queries.</p>\n\n<p>So, a master DB backed by multiple DBs for each client may be a better approach,</p>\n"}, {'answer_id': 20349, 'author': 'Chris Miller', 'author_id': 206, 'author_profile': 'https://Stackoverflow.com/users/206', 'pm_score': 0, 'selected': False, 'text': '<p>If the client would ever need to restore only a single entity from a backup and leave the others in their current state, then the maintenance will be much easier if each entity is in a separate database.  if they can be backed up and restored together, then it may be easier to maintain the entities as a single database.</p>\n'}, {'answer_id': 20472, 'author': 'Tundey', 'author_id': 1453, 'author_profile': 'https://Stackoverflow.com/users/1453', 'pm_score': 0, 'selected': False, 'text': '<p>I think you have to go with the most realistic scenario and not necessarily what a customer "may" want to do in the future. If you are going to market that feature (i.e. seeing all your entities in one dashboard), then you have to either find a solution (maybe have the dashboard pull from multiple databases) or use a single database for the whole app.</p>\n\n<p>IMHO, having the data for multiple clients in the same database just seems like a bad idea to me. You\'ll have to remember to always filter your queries by clientID.</p>\n'}, {'answer_id': 20651, 'author': 'JasonS', 'author_id': 1865, 'author_profile': 'https://Stackoverflow.com/users/1865', 'pm_score': 2, 'selected': False, 'text': '<p>I think this is hard to answer without more information.  </p>\n\n<p>I lean on the side of one database.  Properly coded business objects should prevent you from forgetting clientId in your queries.  </p>\n\n<p>The type of database you are using and how it scales might help you make your decision.  </p>\n\n<p>For schema changes down the road, it seems one database would be easier from a maintenance perspective - you have one place to make them.</p>\n'}, {'answer_id': 32585, 'author': 'Vinnie', 'author_id': 2890, 'author_profile': 'https://Stackoverflow.com/users/2890', 'pm_score': 3, 'selected': False, 'text': "<p>Personally, I prefer separate databases, specifically a database for each entity. I like this approach for the following reasons:</p>\n\n<ol>\n<li>Smaller = faster regarding the queries.</li>\n<li>Queries are simpler.</li>\n<li>No risk of ever accidentally displaying one customer's data to another.</li>\n<li>One database could pose a performance bottleneck as it gets large (# of entities increase).  You get a sort of build in horizontal scalability with 1 per entity.</li>\n<li>Easy data clean up as customers or entities are removed.</li>\n</ol>\n\n<p>Sure it'll take more time to upgrade the schema, but in my experience modifications are fairly uncommon once you deploy and additions are trivial.</p>\n"}, {'answer_id': 504132, 'author': 'Aaron Fischer', 'author_id': 5618, 'author_profile': 'https://Stackoverflow.com/users/5618', 'pm_score': 1, 'selected': False, 'text': '<p>Check out this <a href="http://msdn.microsoft.com/en-us/library/aa479086.aspx" rel="nofollow noreferrer">article</a> on Microsoft\'s site.  I think it does a nice job of laying out the different costs and benefits associated with Multi-Tenant designs.  Also look at the Multi tenancy <a href="http://en.wikipedia.org/wiki/Multitenant" rel="nofollow noreferrer">article</a> on wikipedeia.  There are many trade offs and your best match greatly depends on what type of product you are developing.</p>\n'}, {'answer_id': 1372999, 'author': 'Ian Ringrose', 'author_id': 57159, 'author_profile': 'https://Stackoverflow.com/users/57159', 'pm_score': 0, 'selected': False, 'text': '<p>It also depends on your RDBMS e.g.</p>\n\n<p>With SQL server databases are cheep</p>\n\n<p>With Oracle it is easy to partition tables by customer "customerID", so a single large database can run as fast as a small database for each customer.  </p>\n\n<p>However witch every you choose, try to hide it as a low level in your data access code</p>\n'}, {'answer_id': 1450927, 'author': 'MathGladiator', 'author_id': 131246, 'author_profile': 'https://Stackoverflow.com/users/131246', 'pm_score': 0, 'selected': False, 'text': '<p>Do you plan to have your code deployed to multiple environments?</p>\n\n<p>If so, then try to keep it within one database and have all table references prefixed with a namespace from a configuration file.</p>\n'}, {'answer_id': 2714762, 'author': 'iDevlop', 'author_id': 78522, 'author_profile': 'https://Stackoverflow.com/users/78522', 'pm_score': 0, 'selected': False, 'text': '<p>The single database option would make the maintenance much easier.</p>\n'}]
['https://Stackoverflow.com/questions/20321', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/744/']