Separate database multi tenant architecture

Hi guys, I am from blitzjs. Currently, I want to implement multitenancy on my application and I am looking for separate database option. Unfortunately, blitzjs does not support it. Multitenancy - Blitz.js

Just want to know redwoodjs having this feature?

Hello and welcome !

It sounds totally doable to me, check out the Redwood directives

Cheers!

Al;

  • Redwood Rules !

Is the recommendation here to use a directive on a field like …

…
type Orders {
order_id: @id
…
tenant: uuid! @getTenantFromAuthedUser
…
}

… and then insert the tenantid in the query based on the @getTenantFromAuthedUser directive result?

I have to admit, I’ve not thought a lot about multi-tenancy - I’m sure @dthyresson @thedavid @adriatic will have better ideas/more experience than I do…

I think the best usage of directives is not to access the database to determine if you can access the database but to do everything in memory

To that end I’d probably start by storing the users’ tenantId in the context.currentUser upon login and then access that in the queries - maybe not use a directive after all…

And I don’t know how you’re structuring your data storage. Maybe you’re keeping each tenant’s data in a different [postgres] schema - so you could put the schema name into the context.currentUser…

Or you’re over the top, and doing a different db per tenant then you might be using vanity urls to determine the db to query & forwarding the GQL using GraphQL Mesh (https://www.the-guild.dev/blog/graphql-mesh_

This is the in-depth doc on directives: Directives | RedwoodJS Docs

1 Like