Implement a grayscale publishing system based on Nginx

Software development generally does not come up with the final version, but iterates version by version. New versions will be tested before they go online, but even so, there is no guarantee that there will be no problems when they go online. Therefore, when a new version of code is launched in the company, it is usually tested through the grayscale system. Moreover, the grayscale system can divide the traffic into multiple parts, one part is used for the new version code, and the other part is used for the old version code.

image.png

Moreover, the grayscale system supports setting the proportion of traffic. For example, you can set the process of using the new version of the code to 5%. If there is no problem, set it to 10%, 50%, and finally set it to 100% of the full amount. This can minimize the impact of problems. Otherwise, the full amount will be used as soon as it comes up. If there is an online problem, it will be a big accident. And the grayscale system is not only used for this purpose. For example, if the product is not sure whether certain changes are effective, it needs to do an AB experiment, that is, the traffic must be divided into two parts, one part uses version A code, and the other part uses version B code.

So how is such a grayscale system implemented? In fact, many of them are implemented using nginx. nginx is a reverse proxy service. User requests are sent to it and it is forwarded to the specific application server.

image.png

This layer is also called the gateway layer. It is responsible for forwarding requests to the application server, so naturally you can control the distribution of traffic here, which traffic goes to version A and which traffic goes to version B.

Let’s implement it below:

First, we prepare two versions of the code. Here we create a nest project:

npx nest new gray_test 

Guess you like

Origin blog.csdn.net/xiangzhihong8/article/details/133302937