如何在业务流程过程中捕获数据库中实体的状态?
我请求那些已经处理过这种情况的人分享他们的经验。
用例:
业务订单到达系统>变得活跃>订单已接受或已过期>等待处理>要么成功,要么失败。
你看 ?该实体至少有 4 个状态。我正在做的是,我有一个主表“Order”,然后有四个仅包含 orderId(活动、过期、待处理、已履行)的其他表,并且在查询不同状态的订单时我正在执行 JOINS。
这样,巨大的表 Order 只能被读取而不能被写入,因此从性能的角度来看它非常有效......
对于这个用例,您有哪些技术?
I'm asking those who were already dealing with this situation to share their experience.
Use case :
A business Order comes to a system > becomes active > order is accepted or expired > pending for processing > fulfilled either successfully or not.
You see ? There are at least 4 states of the entity. What I'm doing is that I have a main Table "Order" and then four other tables that contain only orderIds (active, expired, pending, fulfilled) and I'm doing JOINS when querying for orders in different states.
This way the huge table Order is being only read but not written to, so that it is very effective from the performance point of view...
What are your techniques for this use case ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是对的,由于性能原因(写入消除),此用例需要额外的表。但是拥有四个表可能会在后续迭代中带来很多维护麻烦。
我可能只会创建一个 OrderStatusCode 表(orderId、statusId),您可以像这样进行 JOINS
但我感觉对于整个业务周期,实体状态的更改不会超过 6-10 次。将所有内容都放在一张表中应该不成问题。如果您对“where status_id = x”选择的 status_id 有合理的索引。但另一方面,拥有额外的表可以轻松添加一些有关状态代码的附加属性。
You are right that this use case needs additional table(s) because of the performance (writes elimination). But having four tables could cause a lot of maintenance troubles in following iterations.
I'd probably create only a OrderStatusCode table (orderId, statusId) and you can do JOINS like
But I sense that as to the entire business cycle there won't be more then 6-10 changes of the entity state. That shouldn't be problem for having everything in one table. If you have a reasonable index on status_id for "where status_id = x" selection. But on the other hand, having extra table makes it easy to add some additional properties regarding status code.