News for hackers. Stuff that matters.
Re:Ask HN: How come there is no example code for B2B-SaaS apps? by wolco on Sunday May 03, 2020 @01:05AM (#23056980)
Separate table per tenant? Not unless you have/expect 2 to 5 tenants otherwise you run into the issues you describe above.

Having a database per tenant has always interested me. It make sense if the databases will be different (contain other tables)

Adding a tenant id to the tables that require them makes sense.

The best approach is to create a pivot table between users and tenants that holds user_id and tenant_id. Use the primary id of that table to represent the user at that tenant.

Re:Ask HN: How come there is no example code for B2B-SaaS apps? by eloff on Sunday May 03, 2020 @09:45AM (#23058945)
The limit is a lot higher than 2 to 5, but I think sooner or later it will get you. Until then you will suffer a slow death by a thousand migrations.

A separate database is best used if you need an absolute firewall between the tenants for security reasons. Almost no bug can ever let one tenant see the data from another. If they share tables, it's easier to make that mistake.

The downside is you can't have quieres across all your tenants, so you'll want a BI database that brings all the data together anyway.