There are two existing microservices:
User services.
User data fields
uid
allow_withdraw (1: Withdrawal is allowed, 0: Withdrawal is prohibited)
Financial Services
Financial system data fields
account (corresponding to user.uid)
amount (balance)
Now for the withdrawal function, you need to determine allow_withdraw first, and then determine whether the balance is sufficient.
Add a node /users/withdraw
users-service
When executing,
will first determine the allow_withdraw status,
and then request /finance/amount
in finance-service
through HTTP to obtain the balance
Check again whether the balance is sufficient (The problem is here, the judgment here cannot be guaranteed)
What are some good implementation ideas?
Whether the balance is sufficient should not be judged based on the amount the user withdraws or sets a fixed withdrawal amount? Why can't it be guaranteed? As long as the background comparison amount is inconsistent or exceeds, it will fail.