Distributed under the single scene

Now users of the goods orders, our system there are three steps to do:

1. Less inventory of goods.

2. If the user has a red envelope, red envelopes available deducted user.

3. Create an order.

 

Case 1: successful stock trading system deduction, the deduction red envelope success, but this time for some reason (such as overtime) led to the creation order failed.

Q: How to solve the data consistency (C) problem?

A: 1. Create a once failed to improve system availability, we should retry operation (such as: 3). 2

  2. If that fails, it is probably a system problem, and this time we can compensate for the added back after taking inventory, minus the red envelope plus back. The operation failed when we must persist in our operational data.

  3. What principle is distributed thing? The so-called distributed object can be seen as a long thing, local things is something short, this is a long thing turned into a short three things.

 

Q: Retry the above answer should be retried in which part? How to ensure Idempotence?

A: 1. In the data access layer retry behavior it? no problem. Because the order number before creating an order has been generated. Therefore, the data access layer retry does not cause problems of repeat orders.

  2. Yewuluojiceng trading system retry behavior it? No. If all processes no problem, order has been put in storage, the business logic in the transaction call returns a timeout. In this case, the result is returned to the upstream of the failure. But the actual business has been completed. Now if retry, business logic will recreate the order number, assuming that the retry is successful, the system will have two orders. Resulting in repeat orders. How to solve it? User access to the system before the server returned to the user an identification token, and the rear end of the order number that uniquely identifies the binding into the local cache, retry when the cache if there is order number, order number so we remove this retry. Retry the value deleted successfully. If that fails, the information about the persistent failure to facilitate inspection and subsequent compensation.

  3. The gateway layer retry will have the same problem.

 

Q: If you call red button several times without success, how do?

A: The service fuse protection system to avoid an avalanche. Single service is not available, do not affect other available services.

 

Guess you like

Origin www.cnblogs.com/gengshidong/p/11401464.html