API is an essential part of the digital world, and the API gateway bears the heavy responsibility of protecting its security and stability as the first gate of API. Many software engineers and teams used NGINX before but were annoyed by the bottlenecks and restrictions of NGINX. Is there a better alternative?
A great alternative to NGINX is Apache APISIX, then what is Apache APISIX?
What’s Apache APISIX
Apache APISIX is a high-performance, dynamic, full-traffic API gateway. The four notable feature of Apache APISIX:
- The Apache property: APISIX is open source and is also a top-level project of the Apache Software Foundation. It is impossible to modify the open source license midway, as ElasticSearch and MongoDB did. Because APISIX belongs to the Apache Software Foundation (ASF), it is no longer a company or an individual’s project.
- High performance: APISIX is developed based on OpenResty (an NGINX distribution), so APISIX also inherits the power of NGINX itself.
- Dynamic: If NGINX provides a robust underlying architecture, OpenResty adds more possibilities to NGINX by allowing the use of Lua to control the behavior of NGINX. And APISIX, with its flexibility and strong connection to other systems, becomes a fully dynamic API gateway.
- Real-time: APISIX stores the configuration in etcd. This advantage is that configuration changes can be monitored and obtained in real-time through the etcd RESTful API, because etcd itself is a distributed KV database, which is also used by Kubernetes to store the configuration. NGINX uses static files to store the configuration, and if the configuration is updated, the time to reload NGINX will be very long.
Apache APISIX vs NGINX
Since we mentioned that APISIX is developed based on NGINX, you may ask: what is the difference between APISIX and NGINX?
The first thing to note is that the comparison between APISIX and NGINX is not an apple-to-apple comparison. After all, NGINX is a lightweight proxy, and APISIX focuses on making the product’s functions more mature. Also, it has more features because APISIX is redeveloped based on NGINX.
If you are using NGINX as a gateway, the following two advantages of APISIX will give you a more profound feeling.
More flexible configuration
Compared with NGINX’s configuration files, APISIX provides various ways to configure. For example:
- You can configure APISIX via HTTP API. The configuration will be written to etcd, and then synchronized to each node by etcd;
- You can do it with APISIX Dashboard. In APISIX Dashboard, the graphical visualization will help you configure more clearly;
- If you don’t want to use stateful storage methods such as etcd, you can use static files like K8s. APISIX also supports getting individual configurations from local YAML files;
- If you deploy APISIX in K8s, you can use the APISIX Ingress Controller to obtain the configuration issued by CRD;
- If you deploy APISIX as the data plane of Istio, you can also get the configuration issued by Istio by identifying xDS.
Although NGINX also introduced NJS to achieve dynamic control, it is not as ideal as APISIX’s extensibility.
As APISIX can be extended with LuaJIT, it also supports the out-process Plugin Runner to run external plugins written in languages such as Go, Java, Python, Node.js, etc.
In addition, starting from APISIX 2.11, you can run the Wasm plugin. With this function, you can write plugins in APISIX in Rust, TinyGo, and other languages and then compile them into Wasm code to run on APISIX.
Configuring Wasm plugins and Lua plugins in APISIX shows almost no difference in functionality. As a result, it can achieve performance similar to Lua’s native implementation and achieve the development efficiency of high-level languages.
What are the key benefits of Apache APISIX
The advantages described above are pretty good, but they are not the most critical advantages of APISIX. The most significant advantage of APISIX is its ecosystem network interwoven with many projects.
- At the authentication level, APISIX supports protocols such as OIDC and LDAP. At the same time, it can be integrated with multiple authentication services or frameworks, such as Keycloak, Casdoor, Casbin, OPA, etc.
- At the observability level, APISIX supports the connection with multiple log tools, such as Clickhouse, Datadog, Splunk, Apache Kafka, Apache RocketMQ, etc. It can also expose rich metrics through Prometheus to support multiple tracing systems, such as OpenTracing, OpenTelemetry, and Apache Skywalking.
- At the service discovery level, APISIX not only supports obtaining upstream addresses from Nacos, Eureka, Consul, and Zookeeper, but also from DNS (whether through A/AAAA records or SRV records). Furthermore, if you use APISIX as a K8s Ingress Controller, you can get the corresponding configuration from the Ingress resource (APISIX supports the K8s Gateway API specification).
The current APISIX is still in the stage of rapid development. Over time, APISIX will be integrated with more and more projects, opening up more possibilities for cooperation and greatly simplifying the workload of integrating with existing systems.
Suppose the service you want to connect to is not in the APISIX plugin ecosystem. In that case, you can directly use the existing plugins for custom development, achieving functions more specific to your business.
Which API Gateway should you go for
Of course, to choose a suitable gateway, you also need to consider your actual business situation.
If you are already using NGINX as a proxy in front of business applications, and some logic is placed on NGINX, then APISIX will be your best choice. As APISIX is developed based on NGINX, you can smoothly migrate NGINX to APISIX based on your needs.
If you have never used a gateway and want to choose a suitable open-source API gateway project based on your team’s situation, then you need to focus on the following aspects:
- Whether the frequency of updates is good enough. You can choose a well-maintained API Gateway project by observing the activity of each project because no one wants to select a project that goes downhill. You can get a sense of the project activity through the Contributor Over Time graph.
- Whether the functions of the project are complete. If the selected gateway cannot meet the team’s current and future business needs, and because the project adds to the development work (such as configuration management, docking with internal services), please consider carefully.
- Whether some of the project’s complex technical metrics perform well, say, whether QPS, latency, and memory usage meet business requirements. Generally speaking, it is challenging to make subversive optimization of a gateway. Therefore, if a gateway cannot meet these complex metrics, it will be difficult to make breakthroughs no matter how it is iterated later.
- Whether there is enough workforce and time in the team to learn and maintain the API Gateway. After all, technical decision-making is not a purely technical activity.
Of course, if you have used other API gateways, but the gateway cannot meet the current business scenario, then you can use Apache APISIX as one of your options.
How to migrate from Nginx to Apache APISIX
You are wise if you see this and decide to replace your existing NGINX with APISIX!
But before your migrating, you need to brush up on some of the product features you have or are using. Usually these features can be divided into three categories:
- Directly replaceable. APISIX allows users to use NGINX configuration directly, so most of NGINX’s global configuration can be reused by APISIX. As for application-level configuration, it can be replaced by APISIX Routes;
- Requires adjustments, such as changes in metrics;
- Requires additional development
After completing the required development, you would gradually replace NGINX with APISIX in actual business scenarios. During the smooth migration process, you need to consider the following three questions:
- How to proxy client requests to APISIX?
- How to put the equivalent configuration into APISIX and NGINX?
- How to handle both APISIX and NGINX exposed metrics?
You must consider the above three questions and your actual application environment. Finally, don’t forget to prepare the "rollback plan for bugs" in advance.
Through this article, I believe that you have understood the power of Apache APISIX. Let’s try using Apache APISIX as your API gateway!