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
needmorewood
needmorewood3y ago
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)
Keef
Keef3y ago
Maybe take a look at this
Keef
Keef3y ago
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.
needmorewood
needmorewood3y ago
maybe i dont understand what multi tenant means based on reading this
Keef
Keef3y ago
Yeah I was trying to figure out a way how to say it but multi tenancy can mean alot
ibamsey
ibamseyOP3y ago
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.
Keef
Keef3y ago
Ive never gone the subdomain route but just row based access with one domain and it wasnt hard
needmorewood
needmorewood3y ago
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
Keef
Keef3y ago
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
ibamsey
ibamseyOP3y ago
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.
needmorewood
needmorewood3y ago
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
Keef
Keef3y ago
Yeah it is
needmorewood
needmorewood3y ago
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
Keef
Keef3y ago
U wrote that beautifully You can use something like Docker and set variables for different tenants. THen expose these apps using subdomains
needmorewood
needmorewood3y ago
this might be a good reason to decouple FE from BE tbh
Keef
Keef3y ago
It'll still be single codebase, but the dynamic bit comes from the variables you push in from that docker file
needmorewood
needmorewood3y ago
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
Keef
Keef3y ago
Which isnt bad, thats what I was referring to as "row based access"
dan
dan3y ago
^ this is what i am doing at work. but with laravel
Keef
Keef3y ago
Its one way to do it Another is the multi schema way where each org has their own instantiation of your database
needmorewood
needmorewood3y ago
and then write unit tests to make sure authorization works
Keef
Keef3y ago
Thats where prisma fails you since it doesnt support multi schema yet
dan
dan3y ago
each user is added to a tenant and based on that tenant depends what data is fetched
needmorewood
needmorewood3y ago
this is the one time i would really unit test something
ibamsey
ibamseyOP3y ago
I see you've been interested in this for a while. Have you made progress or selected an approach?
Keef
Keef3y ago
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
needmorewood
needmorewood3y ago
i would avoid having a deploy for each customer personally but ur project may very the maintenance cost is awful
Keef
Keef3y ago
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
dan
dan3y ago
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
ibamsey
ibamseyOP3y ago
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.
needmorewood
needmorewood3y ago
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
Keef
Keef3y ago
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
dan
dan3y ago
if only i could show the code i’m working with atm sed
Keef
Keef3y ago
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
dan
dan3y ago
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 sed
Keef
Keef3y ago
I feel for u Hopefully you get to greener pastures or atleast the chance to fix some of those problems
dan
dan3y ago
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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
needmorewood
needmorewood3y ago
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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
needmorewood
needmorewood3y ago
sidekiq
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
needmorewood
needmorewood3y ago
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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ibamsey
ibamseyOP3y ago
great point re testing. Running test servers is such an overhead
Xanacas
Xanacas3y ago
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...
Keef
Keef3y ago
dope Its been a feature request for a long time coming now
Keef
Keef3y ago
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...
Keef
Keef3y ago
interesting solution
ibamsey
ibamseyOP3y ago
good call
Want results from more Discord servers?
Add your server