What Is An API Gateway - by Ashish Pratap Singh
What Is An API Gateway - by Ashish Pratap Singh
201 6 15 Sha
APIs, or Application Programming Interfaces, are a set of rules and protocols that
allows two software applications or services to communicate with each other.
As applications grow in size, the number of APIs increases too. Without the right
tools and infrastructure, managing these APIs can quickly become a challenge.
An API Gateway acts as a central server that sits between clients (e.g., browsers,
mobile apps) and backend services.
Instead of clients interacting with multiple microservices directly, they send their
requests to the API Gateway. The gateway processes these requests, enforces securi
and forwards them to the appropriate microservices.
In this article, we will explore why do we need an API gateway, the key features it
provides and how it works step by step.
If you’re finding this newsletter valuable and want to deepen your learning, conside
becoming a paid subscriber.
As a paid subscriber, you'll receive an exclusive deep-dive article every week, acces
a structured System Design Resource (100+ topics and interview questions), and oth
premium perks.
https://blog.algomaster.io/p/what-is-an-api-gateway 1/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
Clients would need to know the location and details of all backend services.
https://blog.algomaster.io/p/what-is-an-api-gateway 2/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
The API Gateway takes care of routing, authentication, security, and other
operational tasks, simplifying both client interactions and backend managemen
https://blog.algomaster.io/p/what-is-an-api-gateway 3/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
Authentication: Verifying the identity of the client using tokens (e.g., OAuth,
JWT), API keys, or certificates.
By centralizing these tasks, the API gateway eliminates the need for individual
services to handle authentication, reducing redundancy and ensuring consistent acc
control across the system.
https://blog.algomaster.io/p/what-is-an-api-gateway 4/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
2. Rate Limiting
To prevent abuse and ensure fair usage of resources, most API Gateways implemen
rate limiting.
This feature:
Controls the frequency of requests a client can make within a given timeframe.
For example, a public API might allow a maximum of 100 requests per minute pe
user. If a client exceeds this limit, the API Gateway will block additional request
until the rate resets.
3. Load Balancing
High-traffic applications rely on load balancing to distribute incoming requests
evenly across multiple instances of a service.
Redirect requests to healthy service instances while avoiding ones that are dow
or overloaded.
4. Caching
To improve response times and reduce the strain on backend services, most API
Gateways provide caching.
https://blog.algomaster.io/p/what-is-an-api-gateway 5/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
Caching helps in reducing latency and enhancing user experience while lowering
the operational cost of backend services.
5. Request Transformation
In systems with diverse clients and backend services, request transformation is
essential for compatibility.
Modify the structure or format of incoming requests to match the backend serv
requirements.
Transform responses before sending them back to the client, ensuring they me
the client’s expectations.
For instance, it might convert XML responses from a legacy service into JSON fo
modern frontend applications.
6. Service Discovery
Modern systems often involve microservices that scale dynamically.
This ensures seamless request routing even in environments where services frequen
scale up or down.
7. Circuit Breaking
https://blog.algomaster.io/p/what-is-an-api-gateway 6/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
The API Gateway continuously monitors the health and performance of backend
services and uses circuit breaking to block requests to a failing service.
This data helps system administrators detect anomalies, troubleshoot issues, and
optimize the system’s performance. Many API Gateways also integrate with
monitoring tools like Prometheus, Grafana, or AWS CloudWatch.
https://blog.algomaster.io/p/what-is-an-api-gateway 7/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
When you tap "Place Order," the app sends a request to the API Gateway, asking it
process your order.
Your user ID
Delivery address
Payment method
Authentication tokens
The API Gateway receives the request as the single entry point to the backend syste
If any information is missing or incorrect, the gateway immediately rejects the requ
and notifies the app with an appropriate error message.
https://blog.algomaster.io/p/what-is-an-api-gateway 8/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
It checks your permissions to ensure you’re authorized to use the app for placin
an order.
If you’ve made 10 "Place Order" requests in the last minute (maybe by accident)
the gateway might block additional requests temporarily and return 429 Too
Many Requests response.
https://blog.algomaster.io/p/what-is-an-api-gateway 9/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
This ensures the system remains stable and fair for all users specially during traffic
spikes or malicious attacks, such as distributed denial-of-service (DDoS) attempts.
For example:
The app sends the delivery address in plain text, but the Delivery Service expec
GPS coordinates. The API Gateway converts the address into coordinates befor
forwarding the request.
if (!coordinates) {
throw new Error('Failed to fetch GPS coordinates');
}
https://blog.algomaster.io/p/what-is-an-api-gateway 10/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
Inventory Service: To check if the restaurant has your selected items available.
The gateway dynamically routes the request to these services using a load balancin
algorithm, ensuring it connects to available and healthy service instances.
// Select instance
const targetService = selectServiceInstance(services);
// Forward request
return await axios.post(
https://blog.algomaster.io/p/what-is-an-api-gateway 11/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
`${targetService.url}/api/orders`,
req.body,
{ headers: req.headers }
);
};
return transformedResponse;
};
https://blog.algomaster.io/p/what-is-an-api-gateway 12/15
4/21/25, 2:33 PM What is an API Gateway? - by Ashish Pratap Singh
Finally, the API Gateway sends the processed response back to the client in a forma
they can easily understand.
If you found it valuable, hit a like ❤️ and consider subscribing for more such conte
every week.
P.S. If you’re finding this newsletter helpful and want to get even more value, consid
becoming a paid subscriber.
https://blog.algomaster.io/p/what-is-an-api-gateway 13/15