Exploring API Gateways

I am computer science student with a special interest in Backend Engineering!!!
So, everyone in the tech industry knows about APIs. But, what the heck is an API Gateway? Well, that’s what we are going to talk about today.
In this blog, I might refer to the API gateway as the gateway
API Gateway
An analogy →
An API Gateway is like a super-smart receptionist for a building where lots of different businesses operate. Imagine you need to visit several offices within the building, but instead of wandering around and getting lost, you first go to this receptionist.
Thus, it is a piece of software(i.e. receptionist) that intercepts API calls from a user(i.e. you) and routes(i.e. directions to the office) them to the appropriate backend service(i.e. office).
From Wikipedia :
A server that acts as an API front-end, receives API requests, enforces throttling and security policies, passes requests to the back-end service and then passes the response back to the requester.
Enterprise APIs today are deployed via API gateway. Here is an architectural diagram using the API gateway. API gateways provide features like routing, caching, authentication etc. Let's discuss the benefits of using an API gateway.

Advantages of API Gateway
Security → Basic security is taken care of when using the API gateway. Security practices like authentication, authorization, rate limiting, and request throttling are some of the security features gateways come with.
Monitoring and Logging → Gateways come with features like monitoring and logging which especially come in handy when finding the root cause of an error etc. With some gateway services like AWS API Gateway service, you can use analytics services(like cloudwatch) with them to get real-time analytics of your application.
Traffic Management →In my opinion, this is the MVP feature of the API gateway, using techniques like rate limiting, request throttling, load balancing, and authentication. This makes sure that only valid requests reach backend services.
Scalability → API gateways scale dynamically in response to changing workload demands. This makes them both resilient and cost-effective.
But, what about APIs deployed without an API gateway? Well, their architectural diagram may look like this.

As you can see, now each backend service is directly accessible to clients, which allows any request to reach the backend. This reduces security and increases the load on the backend services, thus cost. But, not using an API gateway is sometimes the correct option. This leads us to talk about when to use the API gateway.
When to use API Gateway
API Gateways is useful in several scenarios →
Microservices Architecture → In the case of microservices architecture, an API Gateway is essential for managing and routing requests between the client and various backend services.
Request and Response Transformation → An API Gateway can handle these transformations(e.g., adding headers, changing formats) before passing them to the appropriate service.
Single Entry Point: An API Gateway serves as the central hub through which all requests are processed. This simplifies client interactions by providing a single endpoint.
If your application requires robust security features and controls the number of requests a client can make, protocol translation using an API gateway is the way to go.
In summary, an API Gateway is a great amalgamation of routing, security, traffic management, protocol translation, and monitoring capabilities, serving as a crucial component in modern application architectures.
References:
https://en.wikipedia.org/wiki/API_management
https://learn.microsoft.com/en-us/dotnet/architecture/microservices/architect-microservice-container-applications/direct-client-to-microservice-communication-versus-the-api-gateway-pattern


