Ask HN: How to deal with multi-tenant SaaS database structure?
Hello HN, I'm building a SaaS product. Each tenant can have their own database structure/fields while many tables are common between the tenants.
For example table A is common for all of them while table B might have different fields upon organization/tenant's need, in other words we have table B for all orgs with different fields.
I'm thinking of shared-codebase and shared-database paradigm for it's simplicity(no synchronization needed). Have you encountered this situation? Is it possible/and how to handle this objective with single database for all tenants? Further, I'm using PostgreSQL database.
Thanks in advance.
11 comments
[ 2.6 ms ] story [ 25.9 ms ] threadBut I'd re-think whether a single database is truly the right answer. What is driving you to that solution?
And is consistency across tenants really a hard requirement? Would an eventual consistency model work?
How does migration factor in? Do you mean migrating one database vs multiple databases?
What exactly would you be migrating? And if it’s written in code, migrating individual tenants one at a time, at your pace or when a particular tenant is ready to migrate, might be a feature and not a bug.
Also how much data will each tenant consume?
Separate database will only work if you'll have a handful of customers, and even then a pain.
There are ways you can mitigate this. Strong isolation is one. Throttling tenant calls could be another.
We don’t know your specific use case enough, but it’s something to think about now.
This is generally referred to as the noisy neighbor problem.
https://docs.aws.amazon.com/wellarchitected/latest/saas-lens...