多租户与多个数据库

发布于 2024-09-07 00:31:53 字数 410 浏览 2 评论 0原文

我正在开发一个定制的 CRM 解决方案,该解决方案将通过 Web/SaaS 模型进行销售。我预计会有数十或数百个客户使用此解决方案。我将使用 MS SQL 作为数据库引擎。

选项 1 是使用单个数据库,并在表上包含 TenantId 列、合适的索引,并在每个数据库访问上使用“wheretenantId={...}”。

选项 2 是为每个客户端拥有单独的数据库,从而避免需要 TenantId 和 where 子句。

我预计每个客户将拥有数十万条记录,而不是数百万条。

正如我所看到的,无论我选择哪个选项,都会有一个数据页总数。这个决定似乎集中在 SQL 是否更适合管理多个数据库,或者管理具有 TenantId 和索引的单个数据库。最初,该解决方案将在单个数据库服务器上运行,但最终将转移到 SAN。

有人对此有什么看法吗?

I am developing a custom CRM solution which will be sold via the Web/SaaS model. I anticipate tens or hundreds of clients using this solution. I will be using MS SQL as the db engine.

Option 1 is to have a single DB, and include a TenantId column on tables, a suitable index and use 'where tenantId={...}' on each db access.

Option 2 is to have an individual DB for each client, avoiding the need for the TenantId and where clauses.

I anticipate that each client will have hundreds of thousands of records, not millions.

As I see it, there will be a total number of data pages whichever option I go for. The decision seems centered on whether SQL is better at managing multiple DBs, or a single DB with TenantId and index. Initially the solution will run on a single DB server, but will eventually move to SAN.

Does anyone have any views on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫以 2024-09-14 00:31:53

有一篇有趣的 MSDN 文章,标题为多租户数据架构,您可能想查看一下。作者对某种方法可能比另一种方法更合适的情况进行了简要分析:

的数量、性质和需求
您期望服务的租户都会受到影响
您的数据架构决策
不同的方式。以下一些
问题可能会让你更倾向于
孤立的方法,而其他人可能
使你倾向于更加共享的
方法。

  • 您有多少潜在租户
    期望目标?你可能无处可去
    接近能够估计
    预期使用权威,但是
    从数量级的角度思考:
    您正在构建一个应用程序吗
    数百名租户?数千?十
    数千个?更多的?你越大
    期望您的租户群是
    您更有可能想要考虑
    更加共享的方法。

  • 您期望多少存储空间
    平均租户的数据占用?
    如果您希望部分或全部租户
    存储非常大量的数据,
    单独的数据库方法可能是
    最好的。 (事实上​​,数据存储
    要求可能会迫使您采用
    无论如何,单独的数据库模型。如果是这样,
    设计起来会容易得多
    应用程序从
    开始而不是移动到
    稍后采用单独数据库方法。)

  • 您有多少并发最终用户
    期望普通租户支持?
    数字越大越多
    采取更加孤立的方法
    将满足最终用户的要求。

  • 您希望为每个租户提供任何服务吗?
    增值服务
    ,例如
    每租户备份和恢复
    能力?这样的服务比较方便
    通过更孤立的方式提供
    方法。

请注意,根据您的情况,“共享方法”是选项 1,“隔离方法”是选项 2。对于前两点,你们都没有偏见,所以我想我会根据后两点做出决定。

There is an interesting MSDN article, titled Multi-Tenant Data Architecture, which you may want to check out. The authors make a brief analysis on where a certain approach might be more appropriate than another:

The number, nature, and needs of the
tenants you expect to serve all affect
your data architecture decision in
different ways. Some of the following
questions may bias you toward a more
isolated approach, while others may
bias you toward a more shared
approach.

  • How many prospective tenants do you
    expect to target? You may be nowhere
    near being able to estimate
    prospective use with authority, but
    think in terms of orders of magnitude:
    are you building an application for
    hundreds of tenants? Thousands? Tens
    of thousands? More? The larger you
    expect your tenant base to be, the
    more likely you will want to consider
    a more shared approach.

  • How much storage space do you expect
    the average tenant's data to occupy?
    If you expect some or all tenants to
    store very large amounts of data, the
    separate-database approach is probably
    best. (Indeed, data storage
    requirements may force you to adopt a
    separate-database model anyway. If so,
    it will be much easier to design the
    application that way from the
    beginning than to move to a
    separate-database approach later on.)

  • How many concurrent end users do you
    expect the average tenant to support?
    The larger the number, the more
    appropriate a more isolated approach
    will be to meet end-user requirements.

  • Do you expect to offer any per-tenant
    value-added services
    , such as
    per-tenant backup and restore
    capability? Such services are easier
    to offer through a more isolated
    approach.

Note that the "shared approach" is option 1, and the "isolated approach" is option 2, in your case. You are not biased on either side when it comes to the first two points, so I think I would base my decision on the last two points.

我还不会笑 2024-09-14 00:31:53

如果您不必在租户之间链接数据,那么最好拥有多个数据库。维护更容易,设置更容易,性能也会更好。
当一张表中包含来自多个租户的数据时,表锁定和对大表的搜索查询可能而且很可能会减慢您的解决方案。

共享一个数据库的唯一原因是如果您有很多客户端并且每个客户端的行数非常少。

If you dont have to link data between the tenants, your go best with having multiple databases. Maintenance is easier, setup is easier and performance will be much better.
When having data from multiple tenants in one table, table locks and search querys over big tables can and most likely will slow down your solution.

The only reason to share one db i would see if you have very much clients and very low number of rows per client.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文