<p>I've seen SaaS applications hosted in many different ways. Is it a good idea to split features and modules across multiple databases? For example, putting things like the User table on one DB and feature/app specific tables on another DB and perhaps other commonly shared tables in another DB?</p>

[{'answer_id': 69140, 'author': 'mjallday', 'author_id': 6084, 'author_profile': 'https://Stackoverflow.com/users/6084', 'pm_score': 1, 'selected': False, 'text': "<p>Ask yourself: What do you gain by moving everything into separate databases?</p>\n\n<p>A lot of pain in terms of management would be my guess. I'd be more keen personally to have everything in a single database and if you hit issues that cannot be solved by a single database later then migrate the data into multiple databases.</p>\n"}, {'answer_id': 69152, 'author': 'Chris Gillum', 'author_id': 2069, 'author_profile': 'https://Stackoverflow.com/users/2069', 'pm_score': 2, 'selected': False, 'text': "<p>Having a single database is best for data integrity because then you can use foreign keys.  You can't have this built-in data integrity if you split the data into multiple databases.  This isn't an issue if your data isn't related, but if it is related, it would be possible for your one database to contain data that is inconsistent with another database.  In this case, you would need to write some code that scans your databases for inconsistent data on a regular basis so you can handle it appropriately.</p>\n\n<p>However, multiple databases may be necessary if you need your site/application to be highly scalable (e.g. internet scale).  For example, you could host each database on a different physical server.</p>\n"}, {'answer_id': 69176, 'author': 'Binil Thomas', 'author_id': 3973, 'author_profile': 'https://Stackoverflow.com/users/3973', 'pm_score': 2, 'selected': False, 'text': '<p>Splitting the database by features might not be a good idea unless you see strong evidence suggesting the need. Often you might need to update two databases as part of a single transactions - and distributed transactions are much more harder to work with. Furthermore, if the database needs to be split, you might be able to employ sharding.</p>\n'}, {'answer_id': 69338, 'author': 'Tom Ritter', 'author_id': 8435, 'author_profile': 'https://Stackoverflow.com/users/8435', 'pm_score': 4, 'selected': False, 'text': '<p><a href="http://highscalability.com/" rel="noreferrer">High Scalability</a> is a good blog for scaling SaaS applications.  As mentioned, splitting tables across databases as you suggested is generally a bad idea.  But a similar concept is sharding, where you keep the same (or similar) schema, but split the data on multiple servers.  For example, users 1-5000 are on server1, and users 5000-10000 on server2.  Depending on the queries your application uses, it can be an efficient way to scale.</p>\n'}, {'answer_id': 69347, 'author': 'Vaibhav', 'author_id': 380, 'author_profile': 'https://Stackoverflow.com/users/380', 'pm_score': 3, 'selected': False, 'text': "<p>For SaaS applications, you use multiple databases for multiple tenants, but usually don't split it module-wise.</p>\n\n<p>This is the most common model I have seen in SaaS application design. Your base schema is replicated for each tenant that you add to your application.</p>\n"}, {'answer_id': 69366, 'author': 'Sergey Kornilov', 'author_id': 10969, 'author_profile': 'https://Stackoverflow.com/users/10969', 'pm_score': 6, 'selected': True, 'text': '<p>Start with one database. Split data/functionality when project requires it.</p>\n\n<p>Here is what we can learn from LinkedIn:</p>\n\n<ul>\n<li>A single database does not work</li>\n<li>Referential integrity will not be possible</li>\n<li>Any data loss is a problem</li>\n<li>Caching is good even when it\'s modestly effective</li>\n<li>Never underestimate growth trajectory</li>\n</ul>\n\n<p>Source:</p>\n\n<p><a href="http://www.slideshare.net/linkedin/linkedins-communication-architecture" rel="noreferrer">LinkedIn architecture</a></p>\n\n<p><a href="http://www.slideshare.net/linkedin/linked-in-javaone-2008-tech-session-comm" rel="noreferrer">LinkedIn communication architecture</a></p>\n'}, {'answer_id': 73534, 'author': 'Daniel Fisher  lennybacon', 'author_id': 12679, 'author_profile': 'https://Stackoverflow.com/users/12679', 'pm_score': 0, 'selected': False, 'text': '<p>Keep it a natural design (denormalize as much as needed, normalize as less as required). Split the DB Model into its modules and keep the service oriented principles in mind by fronting data with a service (that owns the data). </p>\n'}, {'answer_id': 342220, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>There are a variety of ways to accomplish it, but the issues of multi-tenancy go deeper than just the data model. I hate to be plugging product, but check out <a href="http://www.apprenda.com" rel="nofollow noreferrer">SaaSGrid</a> by my the company I work at, <a href="http://www.apprenda.com" rel="nofollow noreferrer">Apprenda</a>.We\'re a cloud operating system that allows you to write single tenant SOA apps (feel free to use NHibernate for data access) that automatically injects multi-tenancy into your app. When you publish your app, you can do things like choose a data model (isolated database or shared) and SaaSGrid will deploy accordingly and your app will run without any code changes - just write code as if it were for a single tenant!</p>\n'}, {'answer_id': 782567, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Why to use database at all ?</p>\n\n<p>I think it's good idea to use distributed storage systems like Hadoop, Voldemort  (project-voldemort.com  developed and used by LinkedIn).</p>\n\n<p>I think db good for sensetive data like money operations , but for everything else you can use distributed storages.</p>\n"}, {'answer_id': 65348603, 'author': "Tony O'Hagan", 'author_id': 365261, 'author_profile': 'https://Stackoverflow.com/users/365261', 'pm_score': 2, 'selected': False, 'text': '<p>Have a look at Azure SQL\'s Multi-tenant SaaS database tenancy patterns that details a list of solutions and decision criteria.</p>\n<p><a href="https://learn.microsoft.com/en-us/azure/azure-sql/database/saas-tenancy-app-design-patterns" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/azure/azure-sql/database/saas-tenancy-app-design-patterns</a></p>\n<p>This next discussion includes lots of feedback from devs who\'ve been there done that. The general concensus is avoid multiple databases if you can and enforce tenant only queries automatically. SQL Azure offers row level security to assist in this. It can also be done at the appplication level.</p>\n<p><a href="https://www.indiehackers.com/post/should-i-keep-only-one-database-for-each-customer-in-a-saas-product-2af0af42f4" rel="nofollow noreferrer">https://www.indiehackers.com/post/should-i-keep-only-one-database-for-each-customer-in-a-saas-product-2af0af42f4</a></p>\n<p>One final thought.. choosing single database at the start, does not exclude you from going database per tenant later on. You can even later support many smaller customers in one DB with larger or premium paying customers having their own DB. However starting with database per tenant means your up for a significant migration cost should you later switch back to multiple tenants per database.</p>\n'}]
['https://Stackoverflow.com/questions/69128', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10941/']