同一微服务实例周围的数据一致性
我有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决这是很难解决的问题。您可以使负载平衡器使用粘性会话,以便单个用户请求始终转到单个实例。
无论哪种方式,您都需要确保实现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.