同一微服务实例周围的数据一致性

发布于 2025-02-02 01:54:26 字数 246 浏览 2 评论 0原文

我有5个帐户微服务实例,可将资金从帐户A转移到帐户B,然后在Postgres数据库中更新数据。 我的问题是

一个用户向帐户服务发送了五个请求,我的所有微服务都同时使用每个请求,每个请求都符合所有5个服务方式,但是现在用户在帐户中没有足够的余额,我已经在检查用户是否是否是否有足够的平衡。

但是,在2个请求之后,用户没有足够的余额,因此在请求转到同一微服务的另一个实例之前,我会在混乱中如何检查并实现数据一致性。

我也很想有建议和其他方法

I have 5 instances of account microservice which transfers the money from account A to account B and then updates the data in the Postgres database.
My problem is

A user sent five requests to the account service and all of my microservices are working in parallel each request went to all 5 services way but now the user doesn't have enough balance in the account and I am already checking if the user is having enough balance or not.

but after 2 requests user doesn't have enough balance so I am in confusion how to check this and implement data consistency first before the request goes to another instance of the same microservice.

I would love to have suggestions and other approaches also

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

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

发布评论

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

评论(1

初心未许 2025-02-09 01:54:26

解决这是很难解决的问题。您可以使负载平衡器使用粘性会话,以便单个用户请求始终转到单个实例。
无论哪种方式,您都需要确保实现DB锁定,以便任何时候只能以一致的方式更新一个行。

It's hard problem to solve. You can make load balancer use sticky sessions so that single user requests always go to single instance.
Either way, you need to make sure db locking is implemented so that at any time only one instance can update one row in a application consistent manner.

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