Live data from Hacker News

Ask HN: How to deal with multi-tenant SaaS database structure?

news.ycombinator.com

1–10 of 12 posts

Ask HN: How to deal with multi-tenant SaaS database structure?

#1
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.

Re: Ask HN: How to deal with multi-tenant SaaS database structure?

#3

Possible to do with one database, yes - Add JSON columns to your tables to hold tenant-specific metadata. Deal with it in your app layer. But I'd re-think whether a single database is truly the right answer. What is driving you to that solution?

The main reason: getting rid of synchronization/migration process for many databases.

Re: Ask HN: How to deal with multi-tenant SaaS database structure?

#6

How many tenants and how many clients per tenant will you support? Also how much data will each tenant consume?

It differs for each tenants. Preferably there should be no limit for the number of orgs/tenants. The traffic for each tenant is also varying but it's safe to consider 500req/s.

Re: Ask HN: How to deal with multi-tenant SaaS database structure?

#8

Possible to do with one database, yes - Add JSON columns to your tables to hold tenant-specific metadata. Deal with it in your app layer. But I'd re-think whether a single database is truly the right answer. What is driving you to that solution?

The main reason: getting rid of synchronization/migration process for many databases.

What do you have to keep synchronized across tenants?

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.

Re: Ask HN: How to deal with multi-tenant SaaS database structure?

#10

If one tenant misbehaves and takes down your database, how will your other tenants feel?

What misbehaving do you mean? If traffic is what you mean, it's okay since at the first stage of the software we have time to test/scale accordingly. Therefore in that stage it might make sense to change the architecture to per-tenant database.
Post reply on HN