Nothing is good or bad, thought makes it.
How to realize the system carrying more users is a technical direction that developers need to pay attention to. Generally speaking, the transformation of the structure to improve the bearing capacity is divided into two major directions, which are realized in cooperation with each other.
Hardware architecture improvement,It is mainly implemented using Alibaba cloud’s multi-component cloud environment: through a combination of cloud products with different responsibilities, such as load balancing SLB, template cloned ECs, RDS, shared object storage OSS, etc.
Software architecture optimization,It is mainly the specification of software code development: business decoupling, architecture, microservice, single machine statelessness, file storage and sharing, etc
In the learning process of distributed systems, we also continue to see new knowledge points. Today we want to talk about the implementation of “idempotency” of interface services in software development!
effect:The system should return the same result for multiple requests for an interface! (except for the scenario of network access failure)
Purpose:Avoid repeated business processing caused by repeated requests for various reasons
Repeat request scenario case
1. After the first request from the client, the network exception causes the request execution logic to be received but not returned to the client. The client re initiates the request
2. The client quickly clicks the button to submit, resulting in the same logic being sent to the server many times
Simply divided, business logic can be summarized as addition, deletion, modification and query!
For query, there are no other operations inside. The business that is read-only must meet the idempotent requirements.
For deletion, duplicate deletion requests will at least not cause data clutter. However, in some scenarios, the prompt of repeated clicks is that the deletion is successful, rather than the prompt that the target does not exist.
For addition and modification, here are the key parts to focus on today: new, need to avoid repeated insertion; Modify to avoid invalid repeated modification;
Implementation of idempotency
Implementation method:When the client makes a request, it carries the identification parameter identification, and the server identifies this identification. If the request is repeated, it can return the first result repeatedly.
For example, chestnuts:For example, in the form of the add request, when the add form page is opened, an addid ID is generated, which is submitted to the background interface together with the form.
According to this addid, the server can mark and filter the cache. The cache value can be addid as the cache key and the returned content as the cache value, so that it can be recognized even if the Add button is clicked many times.
When will this addid be updated? Only after saving successfully and clearing the form can the addid ID Id be changed to realize the form submission of new data.