gpt4 book ai didi

multi-tenant - Multi-Tenancy 与租户共享数据

转载 作者:行者123 更新时间:2023-12-04 19:07:00 25 4
gpt4 key购买 nike

我目前正在制作一个将订阅作为 Multi-Tenancy 应用程序出售的 web 应用程序。我使用的技术是导轨。

但是,它不仅仅是使用当前应用程序的孤立租户。

每个租户创建产品并将其发布到他们的个人应用实例上。每个租户都有自己的用户群。

有问题的规范是租户可以将其产品分享给其他租户,以便他们可以转售。

解释 :

FruitShop sells apple oranges and tomatoes.
VegetableShop sells radish and pepper bell.

Fruitshop share tomatoes to other shops.

VegetableShop decide to get tomatoes from the available list of shared items and add it to its inventory.

Now a customer browsing vegetableshop will see radish, pepper bell and Tomatoes.

As you can guess, a select products where tenant_id='vegetableshop_ID' will not work.



我正在考虑与某种 tenant_to_product 建立多对多的关系将具有 tenant_id 的表, product_id , price_id甚至发布开始和结束日期。产品将是一个“半租户表”,其中租户 ID 被租户创建者 ID 替换,以了解谁是原始所有者。

对我来说这似乎很麻烦,添加它意味着复杂的查询,即使对于只销售自己产品的商店也是如此。获得销售的产品会很复杂:
select tenant_to_products.* 
where tenant_to_products.tenant_ID='current tenant'
AND (tenant_to_products.product match publication constraints)

for each tenant_to_product do
# it will trigger a lot of DB call
Display tenant_to_product.product with tenant_to_product.price

取消共享产品还意味着修改所有引用原始产品的tenant_to_products 的复杂更新。

我不确定像这样实现这个约束是个好主意,你建议我做什么?我是打算做一些愚蠢的事情还是一个不错的主意?

最佳答案

正如您已经解决的那样,您将需要对产品机制进行更复杂的订阅。听起来您走在正确的轨道上。

尽可能地抽象信息。例如,不要将表称为“tenant_to_product”,而是将其称为“tenant_relationships”,并将产品 ID 作为该表中的一列。

然后,当租户想要提供服务时,您只需在“服务 ID”表中添加一列,而无需添加整个额外表。

为了提高性能,您可以拥有一个只读数据库服务器,其租户关系会稍微延迟更新。 Azure 或类似的云服务将使这很容易启动。但是,除非您的用户数量超过 100 万,否则可能不需要这样做。

我建议你考虑:

  • 活跃/不活跃(蔬菜店可能更愿意暂时停止销售西红柿,因为它们目前非常有缺陷,直到种植者停止将错误包含在内)
  • 用于通知的服务器端服务,例如“productRemoved”服务。这些服务将批量更改,为用户提供更快的反馈。
  • 不要删除信息,而是设置列 'delete_date' 和 'delete_user_id' 或类似的列。
  • 产品、租户、关系等更改的完整审计历史记录。该表将变得非常大,因此避免读取它并确保更新是异步的,以便调用者不会被阻塞等待表更新。但从商业角度来看,它可能非常有用。

  • 编辑:

    如果您还没有看过,这个相关问题可能很有用: How to create a multi-tenant database with shared table structures?

    关于multi-tenant - Multi-Tenancy 与租户共享数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21915876/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com