【发布时间】:2020-01-13 15:09:59
【问题描述】:
我的应用程序具有以下模型:
class Employee:
name = attr.ib(str)
department = attr.ib(int)
organization_unit = attr.ib(int)
pay_class = attr.ib(int)
cost_center = attr.ib(int)
它工作得很好,但我想将我的应用程序重构为更多的微内核(插件)模式,其中有一个可能只有名称的核心 Employee 模型,并且插件可以添加其他属性。我想也许一种可能的解决方案是:
class Employee:
name = attr.ib(str)
labels = attr.ib(list)
员工可能看起来像这样:
Employee(
name='John Doe'
labels=['department:123',
'organization_unit:456',
'pay_class:789',
'cost_center:012']
)
也许另一种解决方案是为每个“标签”创建一个实体,其中核心员工作为祖先键。此解决方案的一个问题是,目前对实体组的写入限制为每秒 1 次,尽管一旦 Google 将现有数据存储升级到新的“数据存储模式中的 Cloud Firestore”,该限制就会消失(希望很快):
https://cloud.google.com/datastore/docs/firestore-or-datastore#in_native_mode
我认为列表属性和祖先键方法之间的应用程序级权衡是列表方法更紧密地将插件与核心耦合,而祖先键具有更解耦的数据方案(尽管不完全)。
还有其他我应该关注的权衡,性能还是其他方面?
【问题讨论】:
标签: google-cloud-platform google-cloud-firestore google-cloud-datastore