In many cases, we also need to call the third-party interface such as payment, so we have to consider how our system should handle if the third-party side has problems and returns abnormally slow.
There are three common handling methods: downgrade, circuit breaker, and current limiting.
demotion
Downsizing is a service downsizing, where we selectively reduce the availability of some functionality, or turn it off, in order to ensure the availability of core functionality when the pressure on our servers increases. This is a classic case of losing your car. For example, when the server of the website of post bar is overwhelmed, you can choose to close the Posting function, the registration function, change the password, change the profile picture and so on, in order to ensure the core function of login and browsing posts.
Generally speaking, a separate degradation system is established, which can be configured flexibly and in batches. Of course, there are also useful code automatically degraded, such as interface timeout degraded, failed retry multiple degraded, etc. How many times you fail, how long you set the timeout, depends on your business and other factors. Have a little meeting, set a value, throw a line and see what happens. Adjust as necessary.
fusing
A downgrade generally refers to a failure of our own system and a downgrade. Generally, the circuit breaker means that the dependent external interface is faulty and the relationship with the external interface is severed.
For example, if your service A has A function that depends on service B, then service B has A problem and returns slowly. In this case, all functions in A service may be slowed down by such A function, so we need to circuit breaker at this time! When A calls B, it returns an error (or some other default value) and does not request B. I still cite two service calls, some of them are really a link link, a problem is not broken, it is really an avalanche.
Of course, some people think that the circuit breaker is not a kind of downgrade. I think I can’t refute your saying that the circuit breaker is also a kind of downgrade. However, their salient points and meanings are different in nature.
When would be a good time to do it? That is, at what threshold is the circuit breaker reached, 50% of the requests within 5 minutes are over 1 second? Or what? See demotion.
Current limiting
The above two said is a request to come over we have accepted, this limited flow is more ruthless, directly say sorry to the request goodbye! That is, how much capacity the system has set, and only allow these requests to come in, and the rest of them say goodbye.
The general limits are the total number of requests or the total number of requests within a certain period of time.
Total number of requests: for example, kill 100 products, I will put 5000 in, more than the direct rejection request.
Total number of requests in a certain period of time: for example, if the peak number of requests per second is 1W, the additional requests in this second are directly rejected. I’ll see you in a second.
If there is a mistake welcome to correct!
Personal public number: Yes training level raiders
Information about interview progression (distributed, performance tuning, classic book PDF) is available