What is API Gateway and What are the benefits of using it? Let's explore the details through this article right now!
What is API Gateway?
In fact, on average, a microservices system has from a few to hundreds of different services.
And it will be messy if the client communicates with the system without the help of a support method at all.
This is also the reason that API Gateway appears as an intermediary solution, connecting the client and the microservices system in the back.
API Gateway can be likened to a Gateway, the only place leading to the microservices system.
The role of API Gateway is to receive requests from the client side.
Then do the editing - validate - redirect them to the appropriate APIs on the backend services.
Besides the main task of proxy requests, the API Gateway system also often takes on a few other roles such as API security, monitoring, analytics on the number of requests as well as the status of the system.
Benefits of using API Gateway
Don't expose structure of the microservices system to outside
API Gateway helps the client to interact with the microservices system but does not need to call a specific service directly.
At this point, the endpoints of those services will only be called internally.
Therefore, the client will not be able to understand how the backend services are divided.
Besides, refactoring frontend code also becomes simpler for developers.
Frontend code will be cleaner
Since all it takes is call to the API Gateway and no need to track multiple endpoints on each service, the frontend code looks cleaner now, especially as the system gets bigger and bigger.
Monitor & Manage traffic easily
It can be commented that most of the popular API Gateway systems today come with features to monitor - observe - manage traffic through the GUI.
Or sometimes these features will be implemented through the APIs of the Gateway system.
Request caching
API Gateway will also act as the system's load balancer.
Therefore, the request will not be sent directly to the backend, reducing the risk of system overload.
There's an extra layer of system security
Using API Gateway adds an extra layer of protection to the system.
Thereby, effectively preventing common attacks such as DDoS, SQL injection...
Capable of replacing authentication service
API Gateway typically provides a variety of authentication mechanisms.
We can apply it to authenticate users, which saves time and makes the system simpler.
Some limitations of API Gateway
Increases response time
Because it has to go through the intermediate server step, the response will be slower than when calling the system directly.
Increase the error agent
If we want to use API Gateway, we need to do a lot of work such as config, change the code, manage the server...
The above problem makes us have more things to worry about and in the unfortunate event, when the Gateway has an error, the request will not be able to reach the server side.
Slow down the system
If not properly scaled or configured, the Gateway is likely to be overloaded and slow down the system.
Increased costs
When using API Gateway, we have more costs to worry about such as server, electricity, system management...
With “huge” systems, we need to pay more for the enterpise version of the API Gateways.