当前位置:网站首页>How the API gateway carries the API economic ecological chain

How the API gateway carries the API economic ecological chain

2020-11-09 16:55:51 Huawei cloud developer community

Abstract : About how to carry the current rapid development of API Ecological chain , The following is an introduction to API The role of the gateway in it .


API The economic ecological chain has covered the whole world , Most enterprises are already on the road of digital transformation ,API Become the core carrier of enterprise connection business , And generate huge profit space . Fast growing API Scale and call volume , Make the business IT On the architecture 、 There are more challenges to the model . About how to carry the current rapid development of API Ecological chain , The following is an introduction to API The role of the gateway in it .

API What is it?

Application programming interface (Application Programming Interface, abbreviation :API), It is the agreement of linking different components of the software system 【 Wikipedia 】. A simple example : Every time you log in to wechat , You need to provide account information to access , The authentication carrier provided by wechat is a API.API It's everywhere , Finance 、IT、 The Internet of things etc. , The trend is quite rapid , Invisible through our lives .

Looking at the development in recent years ,API There are several common trends in the continuous technical iteration :

1.API The number of openings is increasing

Beyond all doubt , With the development of enterprise data , Micro service transformation , In different fields API Emerge in endlessly , As early as 2014 year ProgrammableWeb I predict API Vector can reach 100,000 To 200,000, And it will continue to grow .API The increase in the number of development opportunities for edge systems , And then it evolved API The emergence of gateways . On a large scale API Management system has become the core development trend .

picture source :The API Economy Disruption and the Business of APIs,Nordic APIs

2.API Diversified service platforms

The original API It mainly aims at the information interaction between network units of different monomer applications , It has evolved into fast communication between services . With artificial intelligence EI,IOT The evolution of , rely on API Our platform is constantly updated , Such as Web,Mobile, Terminals, etc , There will be more service systems in the future .

3. Gradually replace the service mode of the original enterprise ,API That is, goods

Selling calculations , Selling software , Selling capacity , The final enterprise's sales model will gradually change , Liquidity , Unleash the value of data , Depending on different API Management platform creates new profits .

API Why gateway was born

With API The overall trend of the development of , Every historical era faces different challenges , The architecture changes with it , You can refer to it :

picture source :API economy From systems to business services

From the most primitive “ Transport protocol communication ” -> “ Simple interface integration ” -> “ Message middleware ” -> “ standard REST”, You can see API The development of the more concise , Integrate , Normalization , This also promotes the emergence of more system boundary components , Carrying trillions of API In the context of the economy , API Gateway came into being .

Gartner Mentioned in the report : If there is nothing suitable API Management tools , API The economy can't go smoothly . At the same time, it is put forward that for API Life cycle definition of management system : planning( planning ), design( Design ), implementation( The implementation of ), publication( Release ),operation( Operation and maintenance ), consumption( consumption ), maintenance( maintain ) and retirement of APIs( Off the shelf )【 source :Magic Quadrant for Full Life Cycle API Management,Gartner Published in 2016-10-27】.

API Gateway runs through the whole process , And provides rich management features .

  • High performance , Scalable
  • Highly reliable , without interruption of service
  • Plug in API safety control
  • Flexible data choreography
  • Fine fluidization
  • API version management
  • API Data analysis
  • Efficient plug-in routing algorithm
  • Safety certification , Anti attack
  • API Access control
  • Swagger Import and export

API Gateway design core practice

Provide a reference to high performance API Gateway architecture , In the design API The gateway divides the whole into two planes ,API Consumer This is called the data plane ,API Provider This is called the management plane , It can effectively isolate business requests from management requests to a certain extent .

Let's talk about the data plane first

API The core design concept of gateway : Ensure that the data side business is not interrupted . Because of docking API Gateway services are diverse , Customer API The design of the application is uncontrollable , It's very difficult for you to ask every service and client to have fault tolerance , In particular, some of the more traditional businesses . This requires the gateway to ensure that it can handle each request normally , And satisfied with SLA(Service-Level Agreement), Now the industry API There are several gateways : Direct use of cloud services ,Nginx series ,Golang series ,Java Series etc. , More choices , If you want to build your own , Recommended Nginx system , The main considerations are as follows :

1. Restart hot support

Data plane component upgrade is a high-risk action , Once an exception occurs, the connection may be interrupted , System exception , Unless your front end LB( Load balancing ) Capable of rapid drainage , Of course, even so , Or it may cause the request being processed to be forced to be interrupted . So the hot restart of the data plane is very important .

2. Support subscription dynamic routing

API Routing changes are relatively frequent , Timeliness is also required , If you use a periodic synchronization scheme , Syncing tens of thousands of data at once will slow down your system , Therefore, it is very important to add a subscription routing service center , We can quickly subscribe to ETCD In the routing data and real-time effective . And the performance pressure of only taking incremental data will not be too big .

3. Plug in management is supported

Nginx In terms of plug-ins, it provides a rich ecology . Different API, Different users need different processing flow , If every request comes along and follows the same process , There must be related redundant operations . Plug in management can improve performance to a certain extent , It can also ensure that the processing chain can be added quickly during the upgrade process .

4. High performance forwarding capabilities

API Gateways usually work on multiple back ends API Reverse proxy mode , A lot of self-developed API Gateway is prone to bottlenecks in performance , therefore nginx Excellent performance and efficient traffic throughput are its core competitiveness .

5. Stateless and horizontally scalable

API Gateway is the collection of all requests of the whole system , It needs to scale flexibly according to the size of the business , Use the service center to cooperate with Nginx Configuration management can quickly add or delete existing clusters , And sync to LVS, Achieve fast scale out capability .

Let's talk about management

Relative to the data plane , Management constraints are less obvious , Management consideration should be more about the storage and display of data . Define it from the beginning API It's very important to standardize ,Swagger As the most mainstream API Describe patterns , It has a very complete Ecology ,AWS The whole API The gateway model is a reference Swagger To build .


Core practice Architecture

API Gateway related implementation , We will explain flow control and routing traversal today , Other related core designs will be provided in subsequent articles .

Fine second flow control

Flow control over minutes , It's relatively easy to handle , But to second level flow control , It is a great challenge for the performance and processing power of the system . There are many flow control schemes on the Internet , synchronous , Asynchronous has its own advantages , But they all have common problems : Performance and accuracy .

The following is one of the most common flow control schemes ( Cluster flow control ), Use Redis Shared storage records all flow control requests and real-time access , There is an obvious problem with this architecture : When the number of clusters and the number of requests are large ,Redis Cluster performance will become a big bottleneck .

We redesigned a set of API Flow control architecture , Mixed use of multiple flow control schemes , Automatically adjust according to business requirements . Here we divide it into local flow control and cluster flow control . For traffic sensitive applications , The more accurate the flow control accuracy will be required , High timeliness of calculation , The time dimension is low ( Second level ), Using local flow control . For long periods of time , Less frequently visited API We use cluster flow control , Reduce the operation frequency of shared storage .

notes : The above figure shows the specific flow control architecture , And API For gateway integration, please refer to... At the beginning of this chapter API Gateway architecture panorama .

Local flow control

Single machine flow control , Applicable to traffic sensitive business .API according to API-Core Cluster node Computing Hash value , Make sure that each API Can be loaded to one of the cluster nodes . Suppose there is A, B,C Three stations API-Core, If a API Consistency of computation hash The value is A node , When the request is sent to A The node forwards directly from this node , And record a flow control value , When the request is sent to B/C Nodes will be forwarded to A The node calculates a flow control value and forwards it back . This is the same API All the flow control requests will be recorded to one API-Core On . Can use API-Core Single machine flow control capability of . Single machine flow control algorithm is also plug-in , You can count , Leaky bucket, etc .

Of course, local flow control will also bring some problems , When all API All loaded on one node , If one API The number of visits is particularly large , That may lead to uneven load . What's more, if the flow control time record is very long , such as 12 Time / God , The counting time cycle is too long and not suitable for local flow control .

Cluster flow control

Cluster flow control is suitable for long counting period , Flow control accuracy requirements are not high business . It complements the local flow control , Choose different flow control according to different business , The relevant flow control process is basically the same as the above local flow control , But it will cache the flow control data for a period of time locally, and then report it to the flow control center .

Routing traversal algorithm based on tree structure

API The main flow of gateway data plane includes routing matching algorithm , All the data of the route will be cached in ETCD in , In order to improve the performance of data plane , The structure of storage is crucial . In the stored procedure, we have two parts : Domain tree , URI Trees

From the first tree structure, we can traverse the following domain names :www.apig.com, test.com, .apig.com, .com. Domain names are stored from the last “.” To traverse the . give an example :

matching :www.test.com, First match com, Match successful, continue traversing test, Match successfully traversed www, nothing www Matching failure . matching :test.apig.com, First match com, Match successful, continue traversing apig, Match successfully traversed test, nothing test, Traverse Number , Match the target :.apig.com,URL The matching pattern of the domain name is the opposite of that of the domain name , But the traversal algorithm is the same .


The mainstream open source in the industry API There are many gateways , But open source software has one thing in common : Magnitude , Security , Lack of operation and maintenance analysis , To really meet the needs of the production environment , It also requires a high R & D cost . There are specialized skills , Find a perfect one API Management solutions are very important for the realization of enterprise capabilities .

Hua Wei Yun API Gateway Services provide complete API Life cycle management solutions , Support multiple usage scenarios , Provide convenient management service . Give Way API On line , Release , The process of management to the final sale is no longer complex , Quickly realize the realization of enterprise capacity . Welcome to experience :  Hua Wei Yun -API gateway

Welcome to pay close attention to Huawei cloud DevCloud, Search official account :HWDevCloud, Get more information about dry goods !

Click to follow , The first time to learn about Huawei's new cloud technology ~

本文为[Huawei cloud developer community]所创,转载请带上原文链接,感谢