Crazylife's avatar

Setup multi tenant with shared database

I have some questions regarding to multi tenant setup with shared database.

I have different type of tenant e.g. Tenant A - is a shop owner, whereas Tenant B - is a customer. I am using path for Tenant A (shop owner) and subdomain for Tenant B (customer). Customer here also can act as shop owner but feature completely different with Tenant A.

Should i use tenancy package for this kind of structure, or i should make create my own scope? Or any better advice to do it? I have to separate the type of tenant A and tenant B in path and subdomain. Tenant B is actually storefront, while tenant A will only seen by other tenant like Tenant B.

0 likes
5 replies
martinbean's avatar

@crazylife I’m not sure I follow. What does a customer “tenant” do? What do they do with their subdomain?

Crazylife's avatar

@martinbean Tenant B can setup their own store also and sell to consumer, but they don't own a product. They are choosing and selling the product from shop owner. The product chosen and published to their store by Tenant B, and product here belongs to Tenant A.

Maybe i use another way to describe Tenant B type.

For example, Product A belongs to Tenant A (shop owner). Tenant B (basically is a helper to get goods from shop owner and sell). So there will be a relationship for Tenant B and Product from Tenant A. The product from tenant A can link to multiple tenant like Tenant B.

I am actually thinking to differentiate it with '/shop_owner_unique_name_here' for tenant(shop owner), and xxx.domain.com for tenant (helper to sell goods for shop owner).

Is it too complicated, or it's better to make it the same way to define tenant?

The objective I want to achieve it in this way is to identify the type of tenant.

martinbean's avatar

@Crazylife I don’t think you do have different “types” of tenants. You have tenants who have shops. Some tenants still their own products; others sell products from other tenants.

You can just have a nullable foreign key in your tenants table that points to a “parent” tenant. If the foreign key is null then the tenant is a “top-level” one and sells their own products. If the foreign key is not null, then they’re a “child” of another tenant and should sell products from that other tenant.

Crazylife's avatar

@martinbean I don't think it can be done in one table as the tenant can get product from different tenant as well.

E.g. Tenant A is a owner Tenant B is a owner Tenant C is not a owner Tenant D is not a owner

Tenant C/D only can get product from Tenant A/B or both Tenant A and B. But, Tenant C can't get the product from Tenant D, same as Tenant D can't get the product from Tenant C. Both of them only can get from Tenant A/B (owner).

How should I handle this kind of structure?

Can i create a many-to-many relationships table, and type to identify tenant, also with subdomain/path for tenant defined?

martinbean's avatar

@Crazylife Based on your description, all you have is tenants with web shops, and then restrictions on what products a tenant can show in their web shops. Some can create their own products; some can only display products from other specific tenants.

Please or to participate in this conversation.