0
0
HLDsystem_design~12 mins

API gateway concept in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - API gateway concept

An API Gateway acts as a single entry point for clients to access multiple backend services. It handles requests by routing them to the appropriate service, managing security, and sometimes aggregating responses. This simplifies client interactions and improves system scalability and security.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |        |        |
  v        v        v
Service A Service B Service C
  |        |        |
  v        v        v
Database Database Database
  
Cache (optional) 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
Routes requests to appropriate backend services, handles authentication, rate limiting, and response aggregation
Service A
service
Handles specific business logic for a domain or feature
Service B
service
Handles specific business logic for another domain or feature
Service C
service
Handles specific business logic for another domain or feature
Database
database
Stores persistent data for each service
Cache
cache
Stores frequently accessed data to reduce database load and improve response time
Request Flow - 11 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayCache
CacheAPI Gateway
API GatewayService A/B/C
Service A/B/CDatabase
DatabaseService A/B/C
Service A/B/CAPI Gateway
API GatewayCache
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:API Gateway
Impact:All incoming requests fail to route to backend services, causing system unavailability for users.
Mitigation:Deploy multiple API Gateway instances behind the load balancer for redundancy and failover. Use health checks to remove unhealthy instances.
Architecture Quiz - 3 Questions
Test your understanding
What is the main role of the API Gateway in this architecture?
ATo store persistent data for services
BTo route client requests to the correct backend service
CTo balance load between database replicas
DTo cache frequently accessed data
Design Principle
This architecture demonstrates the principle of a single entry point for clients via the API Gateway, which simplifies client interactions and centralizes cross-cutting concerns like authentication and rate limiting. Using a load balancer before the API Gateway ensures scalability and availability. Caching reduces database load and improves response times.