Live data from Hacker News

Ask HN: How come there is no example code for B2B-SaaS apps?

news.ycombinator.com

31–40 of 94 posts

Re: Ask HN: How come there is no example code for B2B-SaaS apps?

#34
post #15

What is the problem just build it your self. A simple template that has a login with a todo list can be extended to have a companies table. When you have added this, you can add a n to n relation between companies and users and poof you have a B2B saas app template.

Having built a number of these, it's not that simple. For example do you put a tenant column on every table, have a separate table per tenant, or have a separate schema or database? There are tradeoffs for each approach and lots of gotchas you wouldn't expect. Like if you use a separate table or database, migrations take forever, you can run into file descriptor limits in your database, etc.

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?

#35

In my experience, a lot of projects start off with shared tenancy (using a tenant id discriminator in the database) and eventually migrate to completely separate schema for each tenant (i.e. a separate “installation” of a single-tenancy app for each tenant) to avoid security and architectural pitfalls. Once you’ve done that, you don’t have to worry about forgetting a `WHERE tenantId = foo` somewhere and leaking data.…

    WHERE tenantId = foo
You only need to do that if you keep multiple tennants in one table. But who does this? Usually in a multi tennant application you have only one line which connects to the tennants DB and thats it. The rest of the code does not have to think about tennants.

Re: Ask HN: How come there is no example code for B2B-SaaS apps?

#36
post #7

Does this help? https://docs.microsoft.com/en-us/azure/sql-database/saas-dbp...

For .NET, we used the web starter kit AspDotNetZero which has multi-tenancy and billing:

https://www.aspnetzero.com/Features

It's a bit pricey but if you don't need the UI or billing then you can use their open source boilerplate code which gives you multi-tenancy:

https://github.com/aspnetboilerplate/aspnetboilerplate

Re: Ask HN: How come there is no example code for B2B-SaaS apps?

#37
http://abp.io/ is probably the best open source one I've seen. They also offer a paid product which is fairly comprehensive. I don't quite like their frontend stuff but the backend side of things is definitely what you're looking for.

There are plenty of paid products in every language which are basically B2B SaaS templates.

ABP, bullettrain, Laravel etc.

Re: Ask HN: How come there is no example code for B2B-SaaS apps?

#39
You should look into Feathers JS [0]. You've the option to write in Javascript or Typescript and its built on top of nodejs/express.

Feathers JS has got builtin authentication and it is easy to add tenants. I've created a quick example and published it here [1], there maybe some rough edges, please mail me if you have any questions.

As others have mentioned with multi tenancy you must have good test cases that verify you've appropriate filters in place to avoid leaking data.

[0] https://feathersjs.com/ [1] https://github.com/bjacobt/feathers-multi-tenant-example

Re: Ask HN: How come there is no example code for B2B-SaaS apps?

#40
post #39

You should look into Feathers JS [0]. You've the option to write in Javascript or Typescript and its built on top of nodejs/express. Feathers JS has got builtin authentication and it is easy to add tenants. I've created a quick example and published it here [1], there maybe some rough edges, please mail me if you have any questions. As others have mentioned with multi tenancy you must have good test cases that verify…

Thanks, will look into it
Post reply on HN