Database for web app with multiple clients

一世执手 提交于 2019-12-22 11:26:13

问题


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).


回答1:


We use a separate set of collections for each client. Our data structure works really well for us and looks like this...

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

Using security rules, we allow clients to read their reportingData and billingData collections, but not the privateData collection.

However, if you need to query data across multiple clients at the same time (for internal use, for example), then Frank's option 1 would work better, with a clientId field.

We do the same thing with users...

/users/{uid}/publicProfile (anyone can read this, only the user can write)

/users/{uid}/userProfile (only the user can read and write)

/users/{uid}/privateProfile (internal data that the user can't read or write)




回答2:


You have a few options for implementing such a multi-tenant solution on Cloud Firestore:

  1. Have all clients in a single set of collections
  2. Have a separate set of collections for each client
  3. Have a separate project for each client

There is no approach which is pertinently better or worse.

I recommend that you at least consider having a separate project for each client. Isolating the clients from each other, makes maintenance and (possibly future) billing a lot easier.

Having all clients in a single set of collections is also possible. You'll just have to make sure that clients can't see each other's data. Since your likely accessing the database directly from the client, use security rules to ensure that clients can only access their own data.



来源:https://stackoverflow.com/questions/48596581/database-for-web-app-with-multiple-clients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!