What is idempotent?
In general, when a service is called, the read service will automatically be transferred to another service request if the call fails. The Write service cannot repeat the request, if the service is not returned successfully because of a time-out or a network failure, the service caller considers it to be a failure, but it is likely that it has succeeded, and it may have serious consequences if it continues to repeat the request for write service, such as the Transfer class service. Therefore, the write service failure can not be designed to continue to send duplicate requests, the service is called to design idempotent, even if the request is repeated, it will not affect.
Know the above background, so, idempotent is the same parameter, repeated requests for the same service, must get the same result.
Power-Equal design
To raise a payment scenario, request a third-party payment interface to initiate the payment function, the same order number, the same amount of information, and the return is successful. The same order number, different amount of information, returns the order number duplicates. This is the idempotent design, the third-party payment is tested when the request parameter and the information of the existing database is consistent, return the existing success data directly, if the data is inconsistent and the order number is repeated directly to the order number. If you do not do idempotent design, the same order number, the same amount of information, repeated payments, may cause the amount of accumulation. For service friendliness, the same amount of information for the same order number return the order number duplicate is also unfriendly.
Some services are inherently idempotent, such as modifying a user's mailbox, gender, and so on, no matter how many times you repeat the request, the result is the same.
Therefore, the key to the design of the power of service is to validate the validity of the request parameters and compare the existing data. If the same request parameters have been processed, do not repeat processing, directly return, this is the idempotent core point.
The following diagram shows the importance of idempotent in a very formal way.
High availability of services: idempotent design