Multi-tenant - easy no?
Am I missing something in plain sight ? Is there a well trodden path / mature framework within typical Next.js Prisma Vercel stacks for implementing a solid multi-tenanted SaaS ? Or is it that everyone rolls their own.
50 Replies
not sure of any frameworks that prescribe multi-tenancy on their own
from my experience its always been something you architect yourself for the most part (maybe some libraries to make certain aspects easier)
Maybe take a look at this
Vercel Documentation
How to Build a Multi-Tenant App with Custom Domains Using Next.js
Create a full-stack application with multi-tenancy and custom domain support using Next.js, Prisma, PlanetScale, and Tailwind CSS.
maybe i dont understand what multi tenant means based on reading this
Yeah I was trying to figure out a way how to say it but multi tenancy can mean alot
Yes, we taken a look at this and it provides a basic example of how to implement, but it's no more that an example. I sort of expected there to be a mature framework in which all the infosec concerns and code structures to prevent client code mistakes would be available.
Ive never gone the subdomain route but just row based access with one domain and it wasnt hard
the article sounds like "many single tenant applications" which is just a single tenant based app but im not confident in this answer atm
might need a theo rant about multi tenancy
I need someone to spoon feed me an opinion
🥺
Multi tenancy has popped up in this discord a bit but i dont think people do it often like that vercel tutorial
Maybe the nextjs has some better knowledge? 🤔
https://discord.com/channels/966627436387266600/966786610362474576/998725710711627776
Heres a theo serving about multi tenancy and prisma
yep. that's about it. You want your customer to have their own database space, no leaks, low risk. You configure a domain an from then on, your code always gets the customer's data. AND, all runs from one repo, one code base and a deploy updates all users systems.
like for instance we have one deploy, one url that holds all of our cusotomers data and we use logic/policies to dicern authorization. thats definitly multi-tenancy in of itself
Yeah it is
inst that single tenant in the theo post
we devs have awful naming when it comes to things
essentially ur asking about single frontend hooking into specific DB/backend parts that are seperated from each other
U wrote that beautifully
You can use something like Docker and set variables for different tenants. THen expose these apps using subdomains
this might be a good reason to decouple FE from BE tbh
It'll still be single codebase, but the dynamic bit comes from the variables you push in from that docker file
have an api endpoint thats tenant based
multi-tenant FE with single tenant backend
or just succumb to putting them all in one db and create like org/team structures
and write logic to prevent bad authorization
Which isnt bad, thats what I was referring to as "row based access"
^ this is what i am doing at work. but with laravel
Its one way to do it
Another is the multi schema way where each org has their own instantiation of your database
and then write unit tests to make sure authorization works
Thats where prisma fails you since it doesnt support multi schema yet
each user is added to a tenant and based on that tenant depends what data is fetched
this is the one time i would really unit test something
I see you've been interested in this for a while. Have you made progress or selected an approach?
I do the org based structure with one app needmorewood & dan mentioned. Its very simple but the trade off is you dont have the control over versioning between tenants if you need that.
If you need versioning, the way I've seen it done is using docker files for each deployment but I havent really dug up too much material on this
i would avoid having a deploy for each customer personally but ur project may very
the maintenance cost is awful
Yeah its messy but some companies do structure it this way
I wished I had one standard platform when I was working with that set up <a:pepe_cry:798287645021175869>
Theres A LOT of infra involved in that second way
let me throw that out there right now
I think if you needed versioning per tenant a better way to setup the project would be using a micro service design. either way it’ll be a lot more work than having a single application that just handles it
yes, this is a key point, depending on the business model. In some cases you are trying to create a production env which is like each customer having a deploy each and a way of releasing new versions from the repo to every deploy. With multi-t it has the same effect, but with a lot less cost.
yes but make sure your reason is damn good
cause its a bad business decision to eat up more costs in both time and money and create more points of failure
so whatever upside you have it better be worth all of that
migration costs are very bad as well
You know what was wild, we even had our AUTH versioned
🥺
I want to say that we always offered newest auth updates to every client but I didnt stick around for long since the code base was a mess and I didn't get as much pull with moving it in the right direction as i wanted
So idkkkkkkkkk
if only i could show the code i’m working with atm
it will never top my no async code base
redux sagas
a GIGANTIC REDUX STORE where you couldn't use dev tools because of the amount of shit stored in it
oh god
laravel, code not indented properly at all. everything is inconsistent. api routes are setup for token auth but token auth doesn’t work so api routes have been placed into “web”. somehow there has been changes to packages vendor (node_modules but for php with composer) so composer install breaks everything
i’m suffering
I feel for u
Hopefully you get to greener pastures
or atleast the chance to fix some of those problems
in time i’ll have everything fixed up
there’s just a lot of code that i need to understand first before i can make any changes
and deadlines such
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
eh, between priority queuing and spinning up more job processors we've scaled to a few million jobs per day no problem personally and could easily scale to a few more million no problem for me at least
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
sidekiq
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
running 4 process on it per ec2 instances and have about 8-10
no- we have no auto scaling we just over built it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
great point re testing. Running test servers is such an overhead
prisma has a very early support for different schema
https://github.com/prisma/prisma/issues/1122#issuecomment-1231773471
GitHub
Support querying across multiple schemas · Issue #1122 · prisma/pri...
Right now with Prisma, you can query across one schema at a time but in many cases, you need to query across multiple tables stored across multiple database schemas. We need to make certain product...
dope
Its been a feature request for a long time coming now
Dario Ielardi's Blog
Schema-Based Multi-Tenancy with NestJS and Prisma
We recently migrated a big NestJS project to adopt Prisma as the ORM. It turned out to be a great decision, and I described our wonderful experience in a recent blog post.
The project is an API backend for a multi-tenant system, where each tenant has...
interesting solution
good call