0
0
Microservicessystem_design~7 mins

Popular gateways (Kong, AWS API Gateway, Nginx) in Microservices - System Design Guide

Choose your learning style9 modes available
Problem Statement
When multiple microservices serve different parts of an application, clients face complexity in managing many endpoints, inconsistent security, and lack of centralized control. Without a unified entry point, it becomes hard to enforce policies, monitor traffic, and handle failures gracefully.
Solution
API gateways act as a single entry point that routes client requests to appropriate microservices. They handle cross-cutting concerns like authentication, rate limiting, logging, and load balancing centrally, simplifying client interactions and improving system manageability.
Architecture
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│               │       │               │       │               │
│    Clients    ├──────▶│  API Gateway  ├──────▶│ Microservices │
│               │       │ (Kong, AWS,   │       │  (Service A,  │
│               │       │  Nginx)       │       │   Service B)  │
└───────────────┘       └───────────────┘       └───────────────┘

This diagram shows clients sending requests to a centralized API Gateway, which routes them to the appropriate microservices.

Trade-offs
✓ Pros
Centralizes security and access control, reducing duplicated effort across services.
Simplifies client-side logic by exposing a single endpoint.
Enables monitoring, logging, and rate limiting in one place.
Supports protocol translation and request aggregation.
✗ Cons
Introduces a single point of failure if not highly available.
Adds latency due to an extra network hop and processing.
Can become complex to configure and maintain at scale.
Use when you have multiple microservices with diverse clients needing unified access, especially at scale above hundreds of requests per second.
Avoid if your system has only one or two services with simple access patterns or very low traffic under 100 requests per second.
Real World Examples
Netflix
Uses Nginx as an API gateway to route requests to various backend services, enabling centralized authentication and traffic management.
Amazon
Uses AWS API Gateway to expose serverless microservices with built-in security, throttling, and monitoring.
Shopify
Uses Kong to manage API traffic, enforce policies, and provide analytics across their microservices ecosystem.
Alternatives
Service Mesh
Operates at the service-to-service communication layer inside the cluster rather than at the client-to-service edge.
Use when: Choose when you need fine-grained control over internal service communication, observability, and security.
Backend for Frontend (BFF)
Creates separate backend services tailored to each client type instead of a single gateway.
Use when: Choose when different clients require highly customized APIs or data aggregation.
Summary
API gateways provide a single entry point to multiple microservices, simplifying client interactions.
They centralize common features like security, monitoring, and traffic control.
Popular gateways include Kong, AWS API Gateway, and Nginx, each suited for different environments and needs.