NGINX, take a back seat, there's a new player in town!
For many developers out there, NGINX would be the primary choice for reverse proxy. However at Decentro, our API platform for banking integrations, we moved on to something more exciting!
API development has moved from a single stack monolithic architecture to the majestic microservices architecture.
This requires a gateway server that should manage redirection, proxying, and security over multiple requests. This means our old faithful NGINX has become a little outdated. (Let’s not even talk about Apache HTTP Server here!)
Even if you run a monolithic application, The API Gateway is still a good pick. Apart from proxying, there are many other benefits.
The API Gateways should give us the developer the ability to:
“But what does it do?”
You may ask. Good question.
Suppose we have an API stack with multiple APIs spanning over a bunch of microservices. Let’s look at the diagram:
Here you can see the API Gateway is the lord and the savior for the application instances running behind it. It proxies the requests to the requisite application instance (as a reverse proxy). Now your endpoint can be independent of the microservice it caters to.
So if you want to have multiple endpoints (e.g., /docs, /documents, /documentation) connected to the same application, you can. Just reverse proxy it, baby!
Here at Decentro, we used to work with NGINX as our reverse proxy server. But we grew out of it. We had to log in to our instance to reload NGINX via CLI and had to learn to manage configurations when using NGINX. It didn’t have consumer-level handling for API management.
We needed something extra. After logging our heads together for quick brainstorming and crossing the Is’ & Ts’ on the Pros/Cons list, we found the one!
Dhumm… Dhumm… Dhumm…
Did you feel it?
Source: Github
As is evident from the image above, Kong provides a lot of features out of the box. No recompilation. No command-line configuration. No extra cost.
Kong comes with its own RESTful Admin APIs. It is built on top of OpenResty (an extension of NGINX) and LuaJIT. These provide access to all kinds of configurations that can be made available. We have done another addition on top of it by adding the Konga dashboard to manage Kong via a GUI.
The API structure in Kong is pretty simple.
So let’s talk about an example.
We have a microservice that takes care of sending emails. We'll declare a Service with the name “emails” (Pretty innovative.. yep!). This will contain the details of the application server, which it will reverse proxy for.
Now let’s make Routes for this service. So we have two kinds of emails to be sent.
Now, we will put an API Key authentication plugin on top of the “emails” service. This will ensure that no bad actors try to get access to our APIs.
We will also add a rate-limit plugin (to limit the number of API hits) on the different routes.
In order to further enhance our security, we will allow only certain IP addresses to be able to access our transactional email route as it will be triggered only by our internal systems, and we know the IP address range for our internal systems.
We will set it open to the world (Potentially insecure) for the marketing emails as the marketing peeps should be able to access it from any cafe that they wish to work out of.
Now we want only authorized consumers to access the APIs, so we will set up a consumer and add the API authentication credentials for them to use.
Now our email service is ready to serve consumers. We can integrate it into our code and give it to the marketing peeps for them to use it manually.
As you can see, using Kong as an API Gateway is simple and takes the hassle of managing APIs. Kong provides many other features like upstreams, certificate management, request and response transformation, serverless code execution, logging, and CORS, which are very helpful when you wish to develop APIs quickly.
NGINX and other reverse proxy servers are simply blown out of the water by the ease of configurability and sheer dexterity that KONG provides out of the box.
We rest our case, thus!