9

我正在构建一个 SAAS 应用程序,我们正在讨论每个客户端一个数据库与共享数据库。我已经阅读了很多,在 SO 中包含了一些主题,但我仍然有很多疑问。

我们的平台应该由每个客户高度定制。(他们应该能够拥有自定义表格并将自定义字段添加到现有表格中)。在这种情况下,多数据库方法似乎很棒。

问题是。我的“用户”表应该在主数据库中还是在每个客户端数据库中?一个用户可能有一个或多个组织,因此它会出现在多个数据库中。另外,国家表等通用表呢?

在主数据库中是有意义的。但是我有很多带有 created_by 字段的表,这些表对用户有一个外键。客户也有一些权限相关的表。

如果有多个数据库,我会失去外键的力量,这意味着对数据库的更多查询。我知道如果它们在同一台服务器中,我可以在数据库之间使用交叉连接,但是我会失去可伸缩性。(我将来可能需要拥有多个数据库服务器)。我对联合表有意见。不确定性能。

我使用的技术是 php 和 symfony 2 框架以及用于数据库的 mysql。

另外,我担心这样一个系统的维护。我们可以创建一些脚本来自动化所有数据库中的模式更改,但是如果我们有 10k 个客户端,这将意味着 10k 个数据库。

您对此有何看法?我的应用程序的主要特征应该是灵活性,所以如果客户需要比基本平台没有的更具体的东西,应该可以为他做。

4

1 回答 1

22

Some classic problems here. Have you ever been to http://highscalability.com/? Some good case studies there.

From personal experience if you try to share clients on one server, you will find that a very successful/active user will take up all the resources of the machine over time. We had one client in a SAAS that destroyed a shared server and we had to move him somewhere else.

I would rip out global enumerations into a service. You can make one central database for things like list of countries, list of states, etc. and put it behind a web service layer. Also in that database you can have user management/managing what server belongs to what user etc. You can make a management portal that reads/writes to this database for managing your user base.

If I was doing a SAAS again, I would start small and wait for the pain to hit. What you really want are good tools to address the scaling issues when they happen. Have some scripts ready to do rolling schema changes across servers (no way to avoid this once you have more than one server). Have scripts to take down machines while you are modifying the schema. Have scripts to migrate a user from a shared server to a dedicated one.

Consider setting up replication from a central database. This would pump down global information that each user partition/database would need without you having to write a lot of code.

But the biggest piece of advice I've seen - and experienced first hand - don't try too hard to build the next Facebook for scale. Start simple and see what actually happens before worrying about major scalability issues. You might be surprised as the user base grows what scales well and what does not.

于 2013-01-28T19:12:34.203 回答