Database for web app with multiple clients

时间:2018-02-03 10:59:54

标签: database angular database-design web-applications google-cloud-firestore

In a real-world web app, how does one go about storing data for multiple clients/companies/customers?

Lets assume we have the following collections for one client:

- users
- tasks

How would I extent this system to a second client? Is there a standard approach?

Note: I am using Firestore (no-sql).

2 个答案:

答案 0 :(得分:1)

我们为每个客户使用一组单独的集合。我们的数据结构非常适合我们,看起来像这样......

/clients/{clientId}/reportingData
/clients/{clientId}/billingData
/clients/{clientId}/privateData

使用安全规则,我们允许客户端读取他们的reportingData和billingData集合,但不读取privateData集合。

但是,如果您需要同时在多个客户端上查询数据(例如,供内部使用),则Frank的选项1可以更好地工作,并使用clientId字段。

我们对用户做同样的事情......

/users/{uid}/publicProfile(任何人都可以阅读此内容,只有用户可以写)

/users/{uid}/userProfile(只有用户可以读写)

/users/{uid}/privateProfile(用户无法读取或写入的内部数据)

答案 1 :(得分:0)

您可以在Cloud Firestore上实施此类多租户解决方案:

  1. 让所有客户都在一组馆藏中
  2. 为每个客户提供一套单独的收藏
  3. 为每个客户创建一个单独的项目
  4. 没有任何方法有针对性地好或坏。

    我建议您至少考虑为每个客户提供一个单独的项目。将客户端彼此隔离,使维护和(可能未来)计费变得更加容易。

    将所有客户都放在一组集合中也是可能的。您只需要确保客户端无法看到彼此的数据。由于您可能直接从客户端访问数据库,use security rules to ensure that clients can only access their own data

相关问题