0
0
Microservicessystem_design~12 mins

API Gateway pattern in Microservices - Architecture Diagram

Choose your learning style9 modes available
System Overview - API Gateway pattern

The API Gateway pattern is used in microservices to provide a single entry point for clients. It handles requests by routing them to the appropriate microservices, aggregating results, and managing cross-cutting concerns like authentication and rate limiting.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |        |         |
  v        v         v
Service A  Service B  Service C
  |         |          |
  v         v          v
Database A Database B Database C
  
Cache (shared or per service) connected to each service
Components
User
client
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Single entry point that routes requests to microservices and handles cross-cutting concerns
Service A
service
Handles specific business logic A
Service B
service
Handles specific business logic B
Service C
service
Handles specific business logic C
Database A
database
Stores data for Service A
Database B
database
Stores data for Service B
Database C
database
Stores data for Service C
Cache
cache
Speeds up data access by storing frequently requested data
Request Flow - 11 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayCache
CacheAPI Gateway
API GatewayService A / B / C
Service A / B / CDatabase A / B / C
Database A / B / CService A / B / C
Service A / B / CAPI Gateway
API GatewayCache
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:API Gateway
Impact:All client requests fail because the single entry point is down; no routing to services occurs.
Mitigation:Deploy multiple API Gateway instances behind the load balancer for redundancy and failover.
Architecture Quiz - 3 Questions
Test your understanding
What is the main role of the API Gateway in this architecture?
ATo store all user data permanently
BTo route client requests to the correct microservice and handle cross-cutting concerns
CTo balance load between databases
DTo cache all data for the system
Design Principle
The API Gateway pattern centralizes request handling, simplifying client interactions and enabling consistent management of security, routing, and caching. It improves scalability by decoupling clients from microservices and allows independent service evolution.