哪种数据模型用于维护客户每天的历史数据

发布于 2025-01-29 04:06:37 字数 91 浏览 2 评论 0原文

我需要维持客户的日常闭合平衡,并在过去365天内根据该平衡绘制线图。优先使用哪种数据模型来维护此数据?

mysql,cassandra或任何其他数据库?

I need to maintain everyday closing balance of a customer and plot a line graph based on that balance for the last 365 days. Which data model is preferred to maintain this data ?

MySQL, Cassandra or any other databases ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

就像说晚安 2025-02-05 04:06:37

显而易见的解决方案是拥有一个具有密钥[客户端ID,数据]的表,并且值为关闭余额。

问题是如何填写这些数据?您可以在一天结束时从事跑步工作。最大的问题是如何使系统可靠?如果工作失败并且第二天重新启动,那会提供前一天的数据吗?

解决此类问题的典型方法是使用“事件采购”。这是一种奇特的方式,说它需要存储在平衡上执行的每个操作的记录。每个添加/扣除都应在那里,包括客户ID和日期。这些记录也可能具有“产生的余额” - 这意味着每天为客户的最后一个操作也具有关闭余额。

最后,您将拥有交易列表,您将能够“重播”上一个事件以获得余额。如果您想拥有每个客户的每日余额的实际表格,这是您的选择 - 因为查找数据而不是每次重新计算数据可能会更便宜。

在银行业中,由于这个特定原因,每笔交易都是单独的记录 - 能够获得不同的报告;包括。每天关闭余额。

The obvious solution would be to have a table with a key [client id, data] and the value being closing balance.

The question is how do you fill that data in? You could have a running job at the day end. The big question is how to make the system reliable? If job fails and is restarted next day, will that provide data for the previous day?

Typical way of addressing this type of problem is using "event sourcing". This is a fancy way of saying that it needs to be a storage of records for every operation executed on a balance. Every add/deduct should be there, including client id and date. These records also may have "resulting balance" - which implies that last operation for a customer in a day has the closing balance as well.

At the end, you will have list of transactions and you will be able to "replay" previous event to get balances. It's your choice if you want to have actual table for daily balances per client - as it may be cheaper to look up that data instead of recalculating it every time.

In banking industry, every transaction is stored as a separate record for this specific reason - to be able to get different reports; incl. closing balances per day.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文