用户的账户余额应该存储在数据库中还是动态计算? [英] should the user's Account balance be stored in the database or calculated dynamically?

查看:49
本文介绍了用户的账户余额应该存储在数据库中还是动态计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户的账户余额应该存储在数据库中还是动态计算?

Should the user's Account balance be stored in the database or calculated dynamically?

为了获得准确的结果,动态计算它是有意义的,但是当有很多用户并且数据库变得非常大时,这可能是一个问题?

For accurate results calculating it dynamically make sense but then it might be a problem, when there are many user's and the database grows very large?

交易

  • ID (PK)
  • 帐户编号
  • 类型
  • 日期时间
  • 金额
  • 等等...等等...

账户余额

  • 事务 ID (PK/FK)
  • 余额

推荐答案

为了保持准确的审计,您应该记录每笔影响用户帐户余额的交易.这意味着您可以动态计算余额,但是出于性能原因,我也会存储余额.不过,为了确保余额正确无误,我每天都会运行一次作业,从头开始重新计算余额.

In order to keep accurate auditing you should make record of every transaction that affects the users account balance. This means you can calculate the balance dynamically, however for performance reasons I would have the balance stored as well. To ensure the balance is correct though, I would have a daily job run that recalculates the balance from scratch.

这篇关于用户的账户余额应该存储在数据库中还是动态计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆