简体   繁体   English

按客户细分Mongo / Postgres数据库的正确策略?

[英]Right strategy for segmenting Mongo/Postgres database by customer?

I'm building a web app (python/Django) where customers create an account, each customer creates/adds as many locations as they want and a separate server generates large amounts of data for each location several times a day. 我正在构建一个Web应用程序(python / Django),客户可以在其中创建一个帐户,每个客户都可以创建/添加任意数量的位置,并且一台单独的服务器每天多次为每个位置生成大量数据。

For example: 例如:

User A -> [locationA, locationB] User B -> [locationC, locationD, locationE] 用户A-> [位置A,位置B]用户B-> [位置C,位置D,位置E]

Where each location is an object that includes name, address, etc. 每个位置都是一个包含名称,地址等的对象。

Every 3 hours a separate server gathers data from various sources like weather, check-ins etc for each location and I need to store each item from each iteration so I can then perform per-user-per-location queries. 每隔3个小时,一台单独的服务器就从各个位置(例如天气,登机等)收集各种数据,我需要存储每次迭代中的每个项目,以便随后可以按用户对每个位置进行查询。

Eg “all the checkins in the last week group by location for User A” 例如,“上周所有分组的签到用户A的位置”

Right now I am using MongoDB and storing a collection of venues with a field of ownerId which is the ObjectID of the owning user. 现在,我正在使用MongoDB,并存储具有ownerId字段(所有者用户的ObjectID)的场所的集合。

What is the best strategy to store the records of data? 存储数据记录的最佳策略是什么? The naïve approach seems to be a collection for checkins, a collection for weather records etc and each document would have a “location” field. 天真的方法似乎是签到的集合,天气记录的集合等,并且每个文档都会有一个“位置”字段。 But this seems to have both performance and security problems (all the access logic would be in web app code). 但这似乎同时存在性能和安全性问题(所有访问逻辑都在Web应用程序代码中)。

Would it be better to have a completely separate DB for each user? 为每个用户拥有一个完全独立的数据库会更好吗? Are there better ways? 有更好的方法吗?

Is a different strategy better if we switch to Postgres/SQL database? 如果我们切换到Postgres / SQL数据库,是否有其他更好的策略?

[GENERAL ADVICE]: I always use Postgres or MySQL as the django ORM connection and then Mongo or DynamoDB for analytics. [一般建议]:我总是使用Postgres或MySQL作为Django ORM连接,然后使用Mongo或DynamoDB进行分析。 You can say that it creates unnecessary complexity because that is true, but for us that abstraction makes it easier to separate out teams too. 您可以说这会造成不必要的复杂性,因为这是事实,但对我们而言,抽象也使分离团队更加容易。 You have your front end devs, backend/ full stacks, and true backend devs. 您拥有前端开发人员,后端/完整堆栈以及真正的后端开发人员。 Not all of them need to be Django experts. 并非所有人都需要成为Django专家。

[SPECIFIC ADVICE]: This sounds to me like you should just get started with mongo. [特定建议]:在我看来,您应该刚开始使用mongo。 Unless you are a B2B SaaS app selling to enterprise companies who won't like a multi-tenet data model then it shouldn't be tough to map this out in mongo. 除非您是向不愿使用多互联网数据模型的企业公司出售B2B SaaS应用程序,否则在mongo中进行映射并不难。 The main reason I say mongo is nice is because it sounds like you don't fully know the schema of what you'll collect ahead of time. 我说mongo很好的主要原因是因为它听起来好像您不完全了解您将提前收集的内容的架构。 Later you can refactor once you get a better handle of what data you collect. 稍后,您可以更好地处理所收集的数据后就可以进行重构。 Expect to refactor and just get the thing working. 期望重构,然后使事情正常进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM