directory

  • Let’s start with the business systems technology stack
  • Gateway routing request forwarding function
  • Gateway provides unified authorization and authentication functions
  • API gateway laminar flow control function
  • API gateway layer grayscale publishing function

Today, I would like to share with you the knowledge of API gateway. Many brothers may usually engage in some CRUD business system development and have never touched API gateway. So today, I would like to talk about what API gateway is and what effect it can play on us. This general interview is also likely to be asked about this knowledge point.

Let’s start with the business systems technology stack

Usually when we write the system, we tend to develop the business code based on spring Boot + Spring MVC + Spring + Mybatis, and then connect to a mysql. You call other systems based on Dubbo. The registry could be ZooKeeper or NACOS, like this one, right?

Gateway routing request forwarding function

Ok, so now to tell everyone about the first pain points, that is your company may have n more business system, the full of beautiful things in eyes, there may be dozens of system, at this time for the front/APP side they will know which request sent to which system, it is really too much trouble, isn’t it, so, at this point would introduce a API gateway.

Each of your business systems will configure in the API gateway what kind of REQUEST URL you want to handle, and then the API gateway receives the request, according to the request URL path to determine which business system should forward the request, perfect, right? Take a look at the picture below.

Gateway provides unified authorization and authentication functions

The next question is, can your system allow people to call you from anyone? You can’t have a process of authorization and authentication, right? You can’t tell if the person who sent the request is good or bad? Don’t you have to think about whether the request sent to you should be processed or not? So you’re doing this authentication thing yourself at this point? That is too troublesome, you also authentication authority, other system oneself also authentication authority, that is really big trouble.

Therefore, at this time, we will directly add the authentication function in the API gateway. If a request comes from a good person or a bad person, the API gateway will authenticate it for you. Only the request that passes authentication can be sent to the back end, as shown in the following figure.

API gateway laminar flow control function

The next pain point comes, that is to assume that our system deployed a total of several machines, a total of thousands of requests per second, the results of one day the operation of a particularly great activity, tens of thousands of traffic and requests per second, all of a sudden to you crushed, you say what you do, you can not carry ah? Each business system can configure its own QPS to limit the number of requests forwarded to you per second, as shown in the following figure.

API gateway layer grayscale publishing function

Then, there is a pain point that we often encounter, that is, every time the system online deployment, if the new version of the deployment to all machines, afraid of the new version online dropped two words, directly crash, how to do. So in general, can introduce a gray level, the gray released it means that, assuming your system has deployed three machines, every time on-line deployment 1 machine first, and then in the online traffic divided 5% to a grayscale version of this new deployment machine, how do you like our first look at, if no problem, the subsequent two machines to deploy again, this is gray.

Gray release can also be called canary, released the canary is what meaning, is the ancient people with piracy before the tomb to throw the canary in the first look, if he don’t call, that grave have poison, the gray released now is also a meaning, the new version first deployed to a machine, look, if he collapsed, means that there is something wrong with the code.

Therefore, grayscale release can be realized based on THE API gateway. After deploying the grayscale version each time, the API gateway will allocate 5% of the traffic to this grayscale version, and then deploy it in full when everything is normal, as shown in the figure below.

Ok, so far, to give you the FUNCTION of the API gateway to explain clearly, you usually do not always bury yourself in writing CRUD code, API gateway these things, but also to understand, do not know anything.

END

Scan code for free 600+ pages of Huisei teachers original fine articles summary PDF

Summary of original technical articles