Interview: Distributed system interface, how to avoid repeated submission of forms?

How to implement a system that carries more users has always been a technical direction that I focus on. The transformation of the structure to increase the carrying capacity is usually divided into two major directions, which are realized in cooperation with each other.

The hardware architecture improvement is mainly based on the use of Alibaba Cloud's multi-component cloud environment: through load balancing SLB, template cloned cloud server ECS, cloud database RDS, shared object storage OSS and other cloud product combinations with different responsibilities.

Software architecture optimization is mainly the specification of software code development: business decoupling, micro-service architecture, stand-alone statelessness, file storage sharing, etc.

In the course of learning distributed systems, I have been constantly seeing new knowledge points. Today, what I want to talk about is the realization of "idempotence" for interface services during software development!

Idempotence

Effect : The system should return the same result for multiple requests to an interface! (Except for scenarios where network access fails)

Purpose : To avoid repeated business processing caused by repeated requests for various reasons

Cases of repeated request scenarios:

1. After the client's first request, the network abnormality caused the request to execute logic but did not return to the client, and the client re-initiated the request

2. The client quickly clicked the button to submit, causing the same logic to be sent to the server multiple times

Simply divide, business logic can be summed up as additions, deletions, changes, and investigations!

For queries , no other operations are included internally, and services that are read-only must meet the requirements of idempotence.

For deletion , repeated deletion requests will at least not cause data clutter. However, in some scenarios, it is more desirable to repeatedly click to prompt that the deletion is successful, rather than the prompt that the target does not exist.

Regarding additions and modifications , here is the part that we will focus on today: adding, you need to avoid repeated insertions; modify, to avoid invalid repeated modifications;

Ways to achieve idempotence

Implementation method : the client brings the identification parameter identifier when making a certain request, and the server recognizes this identifier. If the request is repeated, the first result will be returned repeatedly.

Take a chestnut : For example, in the add request form, when the add form page is opened, an AddId identifier is generated, and this AddId is submitted to the background interface along with the form.

The backend interface can mark and filter the cache according to this AddId. 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 multiple times.

When will this AddId be updated? Only after the save is successful and the form is cleared, the AddId flag can be changed to realize the form submission of new data.

Reader benefits

Thank you for seeing here!
I have compiled a lot of 2021 latest Java interview questions (including answers) and Java study notes here, as shown below
Insert picture description here

The answers to the above interview questions are organized into document notes. As well as interviews also compiled some information on some of the manufacturers & interview Zhenti latest 2021 collection (both documenting a small portion of the screenshot) free for everyone to share, in need can click to enter signal: CSDN! Free to share~

If you like this article, please forward it and like it.

Remember to follow me!
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_49527334/article/details/115372032