API Gateway
An API Gateway is a vital component in modern software architectures, acting as a centralized entry point for managing and routing requests between clients (such as mobile apps, web browsers, or other services) and a collection of backend services or APIs.
API Gateways are especially valuable in microservices architectures, where applications are composed of many loosely coupled services. They simplify the interaction between clients and these services, abstracting away the complexities of individual service communication and providing a single entry point that can be managed, monitored, and secured effectively.
Difference between an API gateway and a load balancer
An API gateway is focused on routing requests to the appropriate microservice, while a load balancer is focused on distributing requests evenly across a group of backend servers.
They can have some intersections but they are not exact same. Usually, they can use together.
Usage of API gateway
- Routing
- Rate limiting and throttling
- Caching
- Authentication and Authorization
- Load balancing
- Monitoring
- Transformation(data)
- Request and response validation
- Circuit breaker
- Service discovery
- API Versioning
- Error Handling
- Service Aggregation
- Web Application Firewall (WAF)
- API Documentation
Even though we list lots of function here, but we seldom use some of them(like waf)
Service discovery
The Service Discovery mechanism helps us know where each instance is located. In this way, a Service Discovery component acts as a registry in which the addresses of all instances are tracked.
Client-Side Service Discovery
The client (requesting service) is responsible for discovering and selecting an appropriate service instance from the registry.
It will bind the registry client with service(coupled)
Server-Side Service Discovery
The alternate approach to Service Discovery is the Server-Side Discovery model, which uses an intermediary that acts as a Load Balancer. The idea is to extract registry service on each client into another layer of load balancer.