High availability of services: idempotent design

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.