An API Gateway Design Strategy Optimized For Persistence and Coupling
An API Gateway Design Strategy Optimized For Persistence and Coupling
Keywords: Microservices play a more and more important role in software development nowadays. Almost every pro-
API gateway gramming language has its own microservices development framework. The characteristics of microservices
Microservices make microservices have cross-platform compatibility issues and inconsistent call standards issues in the process
RPC of development and call microservices. The birth of API Gateway alleviates these problems to some extent. For
Coupling degree
small and medium-sized enterprises using today's popular API Gateways, it is difficult for them to get a balance
Persistence
between cost, performance and maintainability. This paper proposes a scheme to optimize the API Gateway.
Firstly, the framework of API Gateway is optimized. Next, the coupling degree of API Gateway is optimized by
reducing the coupling degree of core services and extended functions. In this way, the optimized Gateway can
adapt to the plug-in mode, improve the user experience and reduce development costs. Then, the persistent
design of the configuration information of the API Gateway is carried out, and the read-write optimization is
carried out so that the optimized API Gateway not only has advantages in the configuration persistence, but also
has further improved the I/O performance. Based on the optimized design, this paper implements a cross
platform compatible API Gateway. Then it compares the performance of two popular API Gateway schemes
through performance testing. The test results show that the optimized design of API Gateway achieves a new
balance among cost, performance and maintainability. At the end of this paper, the work of this paper is
summarized, and the next work is projected.
⁎
Corresponding author at: Henan Key Laboratory of Big Data Analysis and Processing, Henan University, Kaifeng, 475004, PR China.
E-mail addresses: [email protected] (Y. Su), [email protected] (Y. Xie).
https://doi.org/10.1016/j.advengsoft.2020.102878
Received 17 April 2020; Received in revised form 1 June 2020; Accepted 1 July 2020
0965-9978/ © 2020 Published by Elsevier Ltd.
X. Zuo, et al. Advances in Engineering Software 148 (2020) 102878
enterprises and units that need to use the map service. makes Nginx a heavyweight ESB to a certain extent. The problem of
A large number of microservices have generated a large number of excessive coupling will lead to increasing development difficulty and
RPC (Remote Procedure Calls) [5] interfaces, and also a variety of higher development costs, and distributed deployment and cluster de-
calling standards. If a developer uses both Alibaba and Baidu's open ployment after development are more difficult. This is the coupling
microservices, then he/she must understand two different calling rules problem facing the API Gateway.
and the business logic he/she has to be adapted separately. In the case Therefore, for companies facing these problems, they need an API
of joint development by multiple departments or enterprise, different Gateway that is easy to expand, easy to maintain, and pre-examined
departments or enterprises are responsible for implementing a large with performance considerations and optimizations, which is the opti-
number of different microservices, the interface interaction costs will mized design of the API Gateway proposed in this paper. This paper first
become increasingly high, and the large number of microservices will optimizes the framework of the API Gateway and adds a database
increase management and maintenance costs. persistence mechanism. This paper decouples plug-ins with filtering
Facing these problems, API Gateway [6-9] is needed to solve this rules from API Gateway core services as much as possible. This method
problem. API Gateway is a fully managed service that can assist hosted alleviates the problem of high degree of coupling of API Gateway
service developers in developing or services that need to be deployed. business logic to a certain extent. Then based on the optimized fra-
After the developer's RPC service is published on the network, the RPC mework and database persistence mechanism, the database that the
calling address is registered on the API Gateway. The caller sends a plug-in depends on is separated according to business. In this way, the
request to the API Gateway uniformly, the API Gateway forwards the performance impact between the plug-in and the plug-in, and between
caller's request to the registered RPC service to implement the RPC the plug-in and the core business of the API Gateway is reduced as
service call, without having to worry about the diversification of the much as possible, thereby plug-ins in plug-in modules and the core
RPC service's call path. Calling standards are also unified — otherwise business of the API Gateway become microservices, and greatly redu-
the API Gateway will not allow to register this microservice. cing the coupling between the various services of the API Gateway. The
The API Gateway has been developed for many years. Large en- addition of the database persistence mechanism and the design to
terprises such as Amazon, Alibaba, Baidu, and Tencent have developed transform various services into microservices have reduced the devel-
their own API Gateways, and used stable versions as commercial pro- opment and maintenance costs of the API Gateway. In this way, the
ducts for other enterprises to purchase. Organizations like Netflix and above problems can be solved. In addition, the performance optimiza-
the Spring team have also developed their own open source API tion design of the database persistence mechanism is also made in this
Gateways for developers. But for some companies, the cost of using a paper, which lets the company using the API Gateway design strategy of
commercial API Gateway is too high. So they often choose to use an this paper consume less energy in performance optimization.
open source API Gateway. However, using open source API Gateways
often requires additional coding and deployment by users. The coding 2. Maximum optimization strategy of API Gateway
of the API Gateway's filter business is relatively complicated and re-
quires maintenance by experienced developers. The company needs to In the process of selecting an API Gateway, an enterprise can choose
consider the performance indicators of the API Gateway while using it, a commercial API Gateway. Such an API Gateway has been enhanced by
and add some additional modules to optimize the performance of the the high-performance cluster of a large enterprise with hundreds of
API Gateway. millions of users and optimized by a professional team. The deployment
Take an example of the issue of development and maintenance and maintenance problems are solved by a professional customer ser-
costs. The API Gateway that combines SpringCloud and Zuul is a low- vice team, but the cost is high, and even need to pay for the number of
cost solution. The Zuul Gateway is very suitable for microservices ar- calls. For a growing SME (small to medium-sized enterprise, a company
chitecture. The deployment method is like deploying a SpringBoot with no more than 500 employees), this option carries the risk of un-
project. It is easy to be configured and has many ready-made filters. It predictable costs.
also supports custom filters. However, API Gateways such as Zuul, often Enterprises can also choose the popular open source API Gateway
require companies to continue part of the development in order to run technology and use their own development team to develop and build it
smoothly. The construction process is almost the same as setting up a themselves. There is no additional cost for using such an API Gateway,
project combining Spring and Maven, with a large workload and but if there is not enough cost to set up a dedicated team to optimize or
complicated steps. In addition, their routing data is basically stored in build a high-performance cluster, the performance of the built API
the configuration file. It is almost impossible to directly manage the Gateway will often be much lower than the commercial API Gateway.
background data through the background page. If you want to make the For example, the API Gateway combined with Springcloud and Zuul has
configuration and routing information of the API Gateway more con- more complicated configuration and higher deployment and main-
venient for persistent and anti-persistent management, companies often tenance costs. Another example is the API Gateway built on Nginx. The
need to design and implement persistent strategies themselves. For configuration file may be coupled with the logic of service invocation.
``reverse discovery'' API Gateways such as combining SpringCloud and There may be a chain reaction when modifying the filtering rules. This
Zuul (microservices send heartbeats to the Gateway). Once the address also increases the cost of deployment and maintenance in disguise.
of the Gateway changes, not only the consumer needs to modify the In order to better reflect the relationship between these issues, this
configuration, but the microservice needs to modify the configuration paper proposes a new API Gateway design model called the cost-per-
one by one. For a company using an open source API Gateway, the formance-maintainability model of the API Gateway. There are three
above issues can lead to high deployment and maintenance costs. basic attributes in the model.
In order to avoid excessive development costs, some companies will
choose to use Nginx to deploy their own API Gateway. Nginx is a high- • Low-cost index, indicating the degree to which enterprise needs to
performance proxy server that supports external services as an HTTP pay extra in the process of using the API Gateway;
proxy service. The load balancing strategy is simple and the structure is • Maintainable index, indicating the convenience when setting up the
modular. It is different from Zuul. Nginx is easier to deploy or configure API Gateway and the maintenance effort consumed in the process of
than Zuul. The configuration process is all in the configuration file, and using the API Gateway;
the filter components like Zuul are further encapsulated, which can be • The performance index, indicating the length of response time in the
called directly through the configuration file or script. However, as an process of using the API Gateway when facing a large number of
intermediate layer, Nginx couples the logic of service invocation in the microservice consumer requests.
configuration file, which weakens the integrity of microservices and
2
X. Zuo, et al. Advances in Engineering Software 148 (2020) 102878
This paper matches the two choices of the company's API Gateway increases the development cost, and causes a problem of high devel-
with the model. As shown in Fig. 1, the closer the corner of the inner opment cost. If some of the information in the configuration file can be
triangle is to the corner of the outer triangle, the higher the corre- shared with the filter, in the process of developing the filter, there is no
sponding degree to this angle of the outer triangle, and the better the need to worry about message synchronization and special development
effect of the degree. work for reading the information in the configuration file. In addition,
As shown in Fig. 1(a), when an enterprise chooses a commercial API it is more difficult to modify the configuration by the configuration file
Gateway, the deployment and maintenance issues are solved by a method adopted by the API Gateway combining Springcloud and Zuul,
professional customer service team, which means that enterprises using which also causes the problem of high development costs.
commercial API Gateways rarely need to deal with deployment and For the filter of the API Gateway combining Springcloud and Zuul, it
maintenance issues, so the maintainability degree is high. Since the does not have the complete characteristics of microservices, and has a
commercial API Gateway has been optimized by the high-performance high degree of coupling with the core business of the Gateway. After
cluster of a large enterprise with hundreds of millions of users and modifying the filter, the API Gateway system needs to be restarted,
optimized by a professional team [10,11], the performance degree is which causes inconvenience to the cluster deployment and thus the
also very high. However, since companies using commercial API problem of high maintenance cost.
Gateways need to pay high fees, the low cost degree is very low. If the filter can be combined with the database design that has been
As shown in Fig. 1(b), when an enterprise chooses an open source added, the filter can be rewritten as an independent microservice,
API Gateway technology to build an API Gateway by itself, the de- which will reduce the coupling between the filter and the core business
ployment and maintenance need to be performed by the enterprise it- of the API Gateway. If the optimization is performed in the above
self, so the maintainability degree is low. Because the enterprise may manner, the business of modifying a filter only needs to restart the
not set up a high-performance cluster and a professional API Gateway modified microservice instead of restarting the entire system which can
development team, the performance optimization during the con- reduce maintenance costs.
struction of the API Gateway is limited and the performance degree is This article optimizes the framework of the API Gateway based on
low. But because the API Gateway is not required to pay additional fees, the above ideas. The optimized API Gateway (OAPIG) framework is
the low cost degree is high. shown in Fig. 3.
If we can optimize the deployment and maintenance issues, reduce
the coupling degree of each module of the API Gateway, and then im-
3.2. Optimized API gateway framework includes that
prove the performance bottlenecks, we can form a model as shown in
Fig. 1(c), which is the global idea of the API Gateway optimization
design proposed in this paper. Next, the API Gateway will be optimized • API-Gateway Core. API-Gateway Core is the core business of API
Gateway. The core business of the optimized API Gateway is highly
and designed based on the ideas of this model.
streamlined.
• API-Gateway Database. API-Gateway Database is a persistent busi-
3. Optimization of API gateway ness module of API Gateway. This module replaces the configuration
file and related reading services.
3.1. Optimized API gateway framework • Plug-in Module. Plug-in is an extended business module of the API
Gateway. This module replaces the filter part.
Facing the problems of high development cost and high main- • API-Gateway Manager. API-Gateway Manager is a preset visual
tenance cost, the first optimization measure is to optimize the frame- management module plug-in for API Gateway.
work of the API Gateway itself.
The framework of a classic API Gateway consists of a core business About API-Gateway Core, the separated Core module only focuses
module, a filter module, and a configuration module. The core business on the forwarding of consumer requests and the return of the return
module is responsible for the forwarding service of the API Gateway, value of the producer (microservice). The business logic is highly in-
and the filter module is responsible for filtering illegal requests, such as dependent, achieving the characteristics of microservice business logic,
overload request distribution (load balancing filter), overload intercept which greatly reduces the coupling between the core business of the API
(circuit breakers), unauthorized access (authentication control filter), Gateway and other parts. The low coupling design provides great
etc. Some API Gateways need to implement these filters by themselves, convenience for plug-in expansion and cluster deployment. The front
and some API Gateways have some similar filters built in Fig. 2 is the and rear of the core module's business logic are respectively Pre
API Gateway that combines Springcloud and Zuul frame. Component module and Post Component module, which are used to
Zuul supports some filters natively, but also supports custom filters. cooperate with Plug-in to implement filtering business and more plug-in
It can be seen from Fig. 2 that the core business of the API Gateway that services.
combines Springcloud and Zuul mainly deals with configuration files About API-Gateway Database, this module replaces the configura-
and accepts requests filtered by the filter. The filter and the core busi- tion file and related reading services of traditional API Gateway like the
ness of the Gateway do not share configuration data. This increases the API Gateway combining Springcloud and Zuul, then realizes the data-
coding difficulty for developers in the process of filter development, base persistence of configuration information. The routing table and
3
X. Zuo, et al. Advances in Engineering Software 148 (2020) 102878
most configuration information of the optimized API Gateway are database reading-writing interface, and enterprises can also manually
persisted by the database. At the same time, the persistent business open or close a microservice call interface.
logic caches some commonly used data based on memory, which makes By adding a database persistence mechanism, the above framework
the data reliability and reading and writing performance better than separates the plug-in with filtering rules from the core business of the
those of the current open source API Gateway configuration file mode. API Gateway, reduces the coupling between the two, and lays the
About Plug-in, This module replaces the filter part of traditional API foundation for further coupling optimization described in Section 2.3.
Gateway like the API Gateway combining Springcloud and Zuul, and
further microservices the filter and combines it with the database 3.3. Optimization of coupling degree of API gateway business
business to form an independent plug-in, which reduces the main-
tenance cost when the plug-in business is modified. When using the API Based on the framework optimization of the first step, this paper
Gateway, enterprises can choose the pre-extension (plug-in before mi- further optimizes the coupling degree between the API Gateway core
croservices call) and post-extension (plug-in after microservices call) of business and plug-ins, in order to effectively reduce development costs
the plug-in by calling the open database reading-writing interface, so and maintenance costs.
that the new plug-in is constantly added to Plug-in. For example, the The main steps of coupling degree optimization are as follows:
start-stop status field, load number field, and cluster number field of a
microservice exist in the database. Through these fields, plug-ins for 1) . In order to reduce the coupling between the API Gateway core
judging microservice status or for load balancing can be implemented. business and plug-ins, the ``routing table'' and related sub tables in
If enterprises choose to further expand the database fields to a sub-table the database of the API gateway are separated.
in the original database table, a plug-in can be used as an independent 2) . In order to reduce the coupling between plug-ins, the database of
microservice. API Gateway can call this microservice before or after the each plug-in is independent, which also gives the characteristics of
logic of API-Gateway Core. Such business expansion plug-in modules microservice to each plug-in.
are completely microserviced, with extremely low coupling and en- 3) . A kind of plug-in design is added, which is responsible for syn-
hanced usability[12]. This paper will describe this method in details in chronizing core database and plug-in database to enhance the ro-
Section 2.3. bustness of Plug-in Module and prevent plug-in chain failure caused
About API-Gateway Manager, it will show the status of the micro- by a plug-in downtime.
service registered by the current API Gateway by calling the open
4
X. Zuo, et al. Advances in Engineering Software 148 (2020) 102878
All requests of microservice consumers rely on the core business of • Plug-ins that do not need to read the data of the database used by
the API Gateway. If only a certain plug-in or filtering rule is modified, the core business of the API Gateway.
all programs including the core business of the API Gateway need to be • Plug-ins that need to read the database used by API Gateway core
restarted, which will greatly increase maintenance costs. It will also business.
cause losses to consumers of microservices, so this paper needs to op-
timize the coupling degree of the core business of the API Gateway to For plug-ins that do not need to read the database data used by the
ensure that the core business of the API Gateway is not affected by other core services of the API Gateway, such as load balancing plug-ins, it
services like plug-in. only needs to obtain the load status of each microservice. If no new
After the database persistence mechanism is introduced, the in- microservice is registered with the API Gateway, it does not need to
formation in the configuration file is converted into information in the care about the data of the “routing table” database (Core Database in
database table, and this information is divided into different tables Fig. 4) used by the core services of the API Gateway. This means that
according to the attributes. The core table is called the “routing table”. the database tables that this category of plug-in depends on can also be
This table is similar to the router's routing table and stores the corre- separated into an independent database like the API Gateway core
spondence between forwarding paths and objects. For the core services business, such as a database that stores the load status of each micro-
of the API Gateway, the core service only cares about the Gateway service. This plug-in is like a microservice, so the coupling between this
routing table. When the microservice producer registers the necessary category of plug-in and the API Gateway core business and plug-in can
information such as the microservice invocation path and parameters be reduced.
with the API Gateway, the corresponding routing table information is For plug-ins that need to read the database used by the API Gateway
persisted in the database, and the core service only reads the in- core business, because the database used by the API Gateway core
formation of this table. For a ``router'' like API Gateway, only the business is independent, all plug-ins that want to obtain information
“routing table” can complete its basic job [13]. At this time, the core about newly registered microservices must read the “routing table”
business of the API Gateway only depends on the information of a table. database (Core Database in Fig. 4). But it is impossible for all the plug-
This paper can also separate this table into a proprietary database. This ins to read data from the database used by the core business of the API
database only serves the core services of the API Gateway to further Gateway, because this is contrary to the low coupling design. The
reduce the performance impact of other services when reading and purpose of this category of plug-in is to avoid too many unrelated plug-
writing data. ins from reading the core database. Such plug-ins will synchronize some
If the above design is adopted, then the core services of the API newly added necessary data to the independent database of other plug-
Gateway at this time already have the characteristics of microservices, ins. Although this category of plug-in will partially depend on the
which means that it is independent into a microservice that is specifi- business of the first category of plug-in, this category of plug-in does not
cally responsible for request forwarding. The coupling degree between have filtering rules, so even if this category of plug-in fails, it will only
the core services of the API Gateway and other services is extremely affect the unsynchronized plug-ins information and have no effect to
low, because the above design gives the characteristics of microservices existing plug-ins, which will not cause a plug-in failure to cause sub-
to the API Gateway core business. At this time, the coupling degree of sequent dependency plug-in chain failures. For example, during the
the core services of the API Gateway is optimized. operation of API gateway, the database of plug-in A(plug-in that do not
After separating the database associated with the API Gateway core need to read the database data used by the core services of the API
business from the original database, the framework is shown in Fig. 4. Gateway) needs to receive the basic data read by plug-in B(plug-in that
Just optimizing the coupling degree of the core services of the API need to read the database used by the API Gateway core business) from
Gateway cannot completely solve the coupling degree problem, and it is the core database. Suddenly, plug-in B is down due to some failures. At
also very important to reduce the business coupling between plug-ins. If this time, the update of basic data required by plug-in A stops at the
the business coupling between plug-ins is too high, then a plug-in time when plug-in B is down. Then, the information of a new micro-
failure will cause a series of filtering rules to fail. Encountering such service is registered in the core database. In the above scene, only plug-
problems during the deployment process will increase maintenance in A is affected. Plug-in A is affected by its inability to operate on newly
costs. Encountering such problems in an actual production environment registered microservices after plug-in B goes down, but has no impact
will have a serious impact on the producer microservices registered in on other plug-ins, and will not cause the plug-in chain failure. In ad-
the API Gateway. dition, for the core business of the API Gateway, this type of plug-in
The plug-ins in the OAPIG can be divided into two categories: only reads the “routing table” database (Core Database in Fig. 4) and
5
X. Zuo, et al. Advances in Engineering Software 148 (2020) 102878
does not perform other operations, so that the performance impact of from a consumer, the API Gateway core service will necessarily query
the plug-in on the database of the core business of the API Gateway is Core Database based on the information sent by the consumer to find
minimized. the basic information (call path, parameters, etc.) of the microservice
The above design makes the API Gateway core business separated that the consumer needs to consume. If the core business directly reads
from the plug-in as much as possible through database independence, Core Database by calling the database interface, the efficiency is lower
thereby reducing the coupling and performance impact of the core than that of reading from the memory, which is similar to the principle
business and plug-in business. The data table of the first category of of the in-memory database[14].
plug-in is then separated from the original database to form a separate In order to avoid the impact of database reading and writing per-
database, and the first category of plug-in is decomposed into micro- formance bottlenecks, this paper adds an active memory buffer me-
services, which further reduces the impact between plug-ins’ business. chanism between the database and the business module to improve the
The second type of plug-in is responsible for data synchronization, and database reading and writing performance. This article uses a hash
only reads the core business database to reduce the performance im- table as the data structure for the buffered data in the active memory
pact. Finally, the coupling degree optimization of the API Gateway is buffer mechanism. The core of the hash table is a hash function. The
completed. The optimized API Gateway framework is shown in Fig. 5. hash function can convert any input to a compression map with a
After the above-mentioned optimization of the coupling degree, specified length of output, and different inputs may have the same hash
databases originally shared by all plug-ins are separated one by one, so value. Therefore, it is not possible to directly determine the corre-
that one plug-in does not affect the database performance of other plug- spondence between input and output without knowing the hash func-
ins when performing database reading-writing operations. By adding tion. Because of this feature, the hash table has properties such as se-
plug-ins that specifically synchronizes the API Gateway core business curity, integrity, and non-repudiation [15]. In this way, even if the
database and plug-in database data, the problem of data synchroniza- database's encryption protection is lost, the database data can be safely
tion after the database independence is solved, and the database cou- buffered into memory.
pling between the plug-in with filtering rules and the API Gateway core Taking JAVA as an example, a Hash-Map (a key-value hash table
business is minimized, so that it reduces performance impact between provided by JAVA) can be stored directly in the JAVA virtual machine
plug-ins and core business. (JVM), and the data of the JVM is stored in local memory (For the
It can be found that a framework with loose coupling between core purposes of this paper, it is stored on the server where the API Gateway
business and plug-ins, loose coupling between plug-ins and plug-ins, is deployed), the read speed is faster than that of reading a remote
little interference between core business databases and plug-in data- memory database (such as Redis). In this paper, when implementing the
bases, and little interference between plug-in databases has been active memory buffer mechanism, JAVA-based Hash-Map implements
formed. The framework shown in Fig. 5 further reduces the perfor- the storage of database buffered data through the Key-Value data
mance impact and business interleaving between the modules than the structure. The advantages of the Key-Value data structure are high
framework shown in Fig. 3. With a comparison between the framework performance, high scalability, and a simple and flexible data model
shown in Fig. 2 and the framework shown in Fig. 5, the degree of [16].
coupling between the modules in the frame shown in Fig. 5 is greatly The strategy designed in this paper is: If the basic information of the
reduced. microservice that needs to be found is stored in memory, related
business will read directly from memory; otherwise the business con-
3.4. Performance Optimization of API Gateway Persistence Business tinue to read from the database to, but after the reading is finished, the
data read from the database by related businesses need to be buffered
After the introduction of the database and persistence business, the into memory and backed up for the next reading directly read from the
basic information such as the microservice address and calling method memory buffer.
in the Core Database in Fig. 5 is the most frequently read data by the As mentioned above, the Hash-Map based Key-Value data structure
API Gateway core business. If this aspect is not further optimized, the is combined with the local cache of the JVM, and through the active
reading and writing performance of OAPIG will become a new perfor- caching strategy, the active memory buffer mechanism which have
mance bottleneck, and the reading and writing performance of the high-performance, high-reliability, and simple data structure is im-
database will limit the normal distribution of forwarded requests by the plemented.
API Gateway core business. Next, compare the call delay before adding the active memory
For example, after the API Gateway core business obtains a request buffer and the call delay after adding the active memory buffer through
6
X. Zuo, et al. Advances in Engineering Software 148 (2020) 102878
Table 1 Table 2
Experimental environment. Performance improvement ratio of database mode and database mode with
memory buffer.
Software/hardware Model/version
Number of threads Total call duration Total call duration R
CPU Intel Core-i7 7700 (One thread one call) (Has Memory Buffer) (None Memory Buffer)
RAM DDR4-2400MHz 24GB
Disk Samsung 860EVO 1TB 100 374.53 265.25 1.41
DataBase Sqlite Version 3.0 500 639.39 357.14 1.79
JDK Version 11 1000 840.34 405.02 2.07
Springboot Version 2.2.0 5000 1,013.58 490.20 2.07
Springcloud Version 2.2.0 10000 1,179.66 486.45 2.43
Zuul(for springcloud) Version 2.2.0 50000 1,618.18 528.37 3.06
Eureka(for springcloud) Version 2.2.0 100000 1,690.53 556.96 3.04
Nginx Version 1.16.1
Network card Killer E2500 Gigabit Ethernet
Fig. 6. Comparison of response rates between database mode and database mode with memory buffer.
7
X. Zuo, et al. Advances in Engineering Software 148 (2020) 102878
Table 3
The comparison of elements in maintainability.
Elements Springcloud and Zuul Based on Nginx OAPIG
Table 4 structure as the body of the message. JSON is a lightweight data ex-
OAPIG client-to-microservice server data structure. change format. It is based on a subset of ECMAScript (the JavaScript
KEY VALUE specification made by the European Computer Association) and uses a
text format that is completely independent of the programming lan-
Request Source The address of the request source (string) guage to store and represent data. The concise and clear hierarchy
Token Authentication flag (string) to which the request source
makes JSON an ideal data exchange language. It is easy for humans to
was assigned
Request Parameters All input parameters required by the microservice
read and write, it is also easy for machines to parse and generate, and
Service Name Service name registered with the OAPIG effectively improves network transmission efficiency[18].
In the core business part of the API Gateway, HPROSE is introduced
as the RPC call engine library. HPROSE will automatically encapsulate
The element of design of low coupling plug-in indicates whether the JSON datagrams into HTTP datagrams. In this way, microservice con-
API gateway considers microservice plug-ins. Nginx couples the logic of sumers only need to provide a JSON containing the microservice name,
service invocation in the configuration file, which weakens the integrity parameter sequence, and description information. The key-value
of microservices and makes Nginx a heavyweight ESB to a certain ex- structure of the JSON object is easy to understand, simple to assemble,
tent. So the Nginx-based API Gateway does not have this element. and only needs to call an interface when using HPROSE.
The element of design of Highly available plug-in indicates whether Because the optimized API Gateway already has the characteristics
the API gateway has high availability design for failure of plug-ins. As of microservices, this paper relies on the Springboot framework[19] to
described in Section 3.2, OAPIG has this mechanism. implement it and deploy it based on the Springboot deployment
The element of the active memory buffer mechanism indicates method.
whether the API gateway has special memory optimization for the The implementation process is as following.
persistent business. As described in Section 3.3, OAPIG has this me- Step 1: the definition of the data structure. Here JSON is used for
chanism. data communication. During the communication process of the opti-
The element of compatible with Spring technology stack indicates mized API Gateway, the datagram from the client to the microservice
whether the API gateway supports the framework under the spring contains the authentication code (token), the request source, the re-
technology stack. As described in Section 3.3, OAPIG has this me- quested service name and input parameters sequence. As shown in
chanism. Table 4.
Nginx requires additional development of compatible programs to During the communication process of the optimized API Gateway,
support the Spring technology stack. Zuul supports Spring technology the datagram from the microservice to the client contains the request
stack, and the design of OAPIG can also be compatible with spring source, the microservice return code (for quickly identifying the status
technology stack, this paper will introduce the implementation of of this call), the microservice return message (used to describe the
OAPIG based on Spring technology stack in Section 4.1. status of this call in more detail) and the return value sequence. As
shown in Table 5.
4. Testing procedure The information of the service name and the input parameters re-
quired by the microservice are registered on the API Gateway in ad-
4.1. Implementation of the optimized API gateway vance by the developer of the microservice or the enterprise using the
API Gateway. After the caller views the information, the caller can
The first step for a microservice consumer to access the API Gateway assemble the input sequence of the microservice according to the in-
is to send an access request. This request generally contains the name of formation format displayed by the API-Gateway Manager.
the requested microservice, the input parameter sequence, and other Step 2: implementation of API Gateway services. HPROSE is used as
descriptive information. The API Gateway that combines Springcloud OAPIG's RPC call engine library. The programming language used is
and Zuul and the Nginx-based API Gateways all accept HTTP data- JAVA. The database is SQLITE. The database connection pool is JDBC
grams. The datagram messages need to be assembled by microservice provided by JAVA. The focus here is on the API Gateway core service
consumers themselves. Such messages are not easy to understand or development process. The first is to complete the encoding of the for-
parse. warding part according to the HPROSE document standard; then add
Therefore, this article redefines the data structure of the message, the parameter analysis encoding before forwarding the business to
and takes the JavaScript Object Notation (JSON) [17] key-value data determine the name of the requested microservice, and go to the
Table 5
OAPIG microservice-to-client server data structure.
KEY VALUE
Code Return code attached to the result which contains a simple state of the call
Message Detailed call status descriptions and remarks for returned results
Return Values Result information calculated based on parameters sent from the client
Request Source Client's address
8
X. Zuo, et al. Advances in Engineering Software 148 (2020) 102878
database and memory buffer to find the address. If an enterprise using performance optimization of the persistent service, this paper imple-
OAPIG needs to add a plug-in or filter, it should call the plug-in's mi- ments and deploys an API Gateway according to the optimization idea.
croservice interface here; finally, after forwarding the business, add In order to prove that the coupling degree optimization of the API
logic that wraps the microservice return value and returns the return Gateway will not affect the performance of the API Gateway and prove
value to the request source. the effectiveness of the performance improvement of the persistence
The pseudocode of OAPIG core business is: service combined with other business of modules in the framework after
performance optimization, this paper conducted a performance test.
The experimental environment used in this section is shown in
1 public JSONObject apiGateway(String serverName,Object[] args) {
Table 1.
2 //pre-components
3 Pre_plugin1(serverName, args); The test comparison object is the API Gateway combined with
4 Pre_plugin2(serverName, args); Springcloud and Zuul (hereinafter abbreviated as SCZAPIG), and the
5 //You can insert more plugins(pre-components) at here API Gateway (hereinafter abbreviated as NAPIG) built on Nginx
6 //get a micro-service's real IP-address (hereinafter abbreviated as NAPIG); The microservices registered on the
7 if(AddressCache.has(serverName)) {
8 //try to get address from RAM
API Gateway for testing only return the input parameters and have no
9 serverAddress=AddressCache.getAddress (serverName); computing services to avoid the impact of the computing business of the
10 }else { microservices on the test. The source of access to microservices, the API
11 //get address from Database Gateway, and the program deployment environment of the micro-
12 serverAddress=serverFind.getAddressfromDB(serverName);
services are same. The three API Gateways did not add any filtering
13 Addresscache.put(serverName, serverAddress);
14 } rules with computing business to avoid the impact of the filtering rules
15 //send request message to a micro-service and get return-value on the performance.
16 JSONObject content=SendbyHprose(serverAddress, serverName, Seven groups of experiments were performed separately. The 1st
args); group included 2000 threads full calling, the 2nd group included 4000
17 //post-components
18 Post_plugin3(serverName, args, content);
threads full calling, the 3rd group included 8000 threads full calling,
19 Post_plugin4(serverName, args, content); the 4th group included 16000 threads full calling, the 5th group in-
20 //You can insert more plugins(post-components) at here cluded 32000 threads full calling, the 6th group included 64,000
21 return content; threads full calling, and the 7th group included 128,000 threads full
22 }
calling, the microservice registered on the Gateway are called once per
thread. After obtaining the test results, calculation was made by for-
Step 3: deployment. The API Gateway is deployed as an independent mula (1).
microservice in the SpringBoot framework. The producer microservices
are all independent microservices and deployed in the SpringBoot fra-
5. Results and discussion
mework. The client simulates HTTP calls through JAVA and acts as a
separate Java Archive package, which is started during testing.
5.1. The experimental results are shown in Fig. 7
4.2. Test With the experimental results shown in Fig. 7 for further calculation
and analysis, the response rate improvement ratio is obtained by using
After optimizing the coupling degree of the API Gateway and the formula (2). Where is the response rate improvement ratio, r_0
9
X. Zuo, et al. Advances in Engineering Software 148 (2020) 102878
10
X. Zuo, et al. Advances in Engineering Software 148 (2020) 102878
11