| Users | Requests per Second (RPS) | API Gateway Load | Microservices Load | Network Traffic | Notes |
|---|---|---|---|---|---|
| 100 users | ~50 RPS | Single instance handles easily | Microservices handle requests directly | Low | Simple setup, no scaling needed |
| 10,000 users | ~5,000 RPS | API Gateway needs horizontal scaling | Microservices start to see increased load | Moderate | Introduce load balancer, caching at gateway |
| 1,000,000 users | ~500,000 RPS | Multiple API Gateway instances behind LB | Microservices require scaling and partitioning | High | Use caching, rate limiting, and circuit breakers |
| 100,000,000 users | ~50,000,000 RPS | Global distributed API Gateways with CDN | Microservices sharded and geo-distributed | Very High | Advanced routing, edge caching, and autoscaling |
API Gateway pattern in Microservices - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
The API Gateway becomes the first bottleneck as it handles all incoming requests. At moderate to high traffic (around 10,000 users or 5,000 RPS), a single gateway instance struggles with CPU and network limits. This causes increased latency and potential request drops.
- Horizontal Scaling: Add multiple API Gateway instances behind a load balancer to distribute traffic evenly.
- Caching: Implement response caching at the gateway to reduce calls to microservices.
- Rate Limiting: Protect backend services by limiting request rates per user or IP.
- Sharding Microservices: Partition microservices by user region or function to reduce load.
- CDN Integration: Use Content Delivery Networks for static content and edge caching to reduce gateway load.
- Circuit Breakers: Prevent cascading failures by stopping calls to failing microservices.
- At 10,000 users (~5,000 RPS):
- API Gateway CPU: ~50% utilization per instance (assuming 2,000 RPS per instance)
- Network bandwidth: ~500 Mbps (assuming 100 KB per request/response)
- Storage: Minimal at gateway, microservices storage depends on data
- At 1,000,000 users (~500,000 RPS):
- Need ~250 API Gateway instances (500,000 / 2,000 RPS per instance)
- Network bandwidth: ~50 Gbps
- Microservices require database scaling and caching layers
Start by explaining the role of the API Gateway as a single entry point. Discuss how it simplifies client interactions but can become a bottleneck. Then, outline scaling steps: horizontal scaling, caching, rate limiting, and microservices partitioning. Always justify why each step is needed based on traffic growth.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas and implement caching to reduce direct database load before scaling vertically or sharding.
Practice
API Gateway in a microservices architecture?Solution
Step 1: Understand the role of API Gateway
An API Gateway serves as a single entry point that routes client requests to the appropriate microservices.Step 2: Eliminate incorrect roles
It does not store data, replace databases, or manage internal microservice logic; those are handled by other components.Final Answer:
It acts as a single entry point to route requests to multiple microservices. -> Option AQuick Check:
API Gateway = Single entry point [OK]
- Confusing API Gateway with database or service logic
- Thinking API Gateway manages microservice internals
- Assuming API Gateway stores data
Solution
Step 1: Identify API Gateway responsibilities
API Gateway routes requests, manages security like authentication, and can combine responses from multiple services.Step 2: Remove incorrect options
It does not execute business logic itself, store data permanently, or replace microservices.Final Answer:
API Gateway routes requests, handles authentication, and aggregates responses. -> Option DQuick Check:
Routing + Security + Aggregation = API Gateway [OK]
- Thinking API Gateway runs business logic
- Confusing API Gateway with data storage
- Assuming API Gateway replaces microservices
Solution
Step 1: Analyze the request flow
The API Gateway receives one client request and internally calls multiple services, then combines their responses.Step 2: Understand the benefit
This reduces the number of requests the client must make, simplifying client logic and improving efficiency.Final Answer:
It reduces the number of client requests by aggregating responses. -> Option BQuick Check:
Response aggregation reduces client calls [OK]
- Thinking client must call each service separately
- Believing API Gateway increases client requests
- Confusing aggregation with service removal
Solution
Step 1: Identify the error source
If clients get errors when calling multiple services via the API Gateway, routing issues are a common cause.Step 2: Exclude other causes
Microservices usually have APIs; clients bypassing the gateway would not cause errors through it; storing data is not the gateway's role.Final Answer:
The API Gateway is not properly routing requests to the correct microservices. -> Option CQuick Check:
Routing errors cause client failures [OK]
- Blaming microservices for missing APIs
- Assuming clients bypass the gateway
- Thinking API Gateway stores client data
Solution
Step 1: Understand response aggregation purpose
Response aggregation combines data from multiple microservices into a single response, simplifying client handling.Step 2: Evaluate other options
Increasing network calls or forcing clients to manage authentication per service adds complexity; storing data centrally is not the gateway's role.Final Answer:
To reduce client complexity by combining data from multiple services into one response. -> Option AQuick Check:
Aggregation simplifies client responses [OK]
- Thinking aggregation increases client calls
- Assuming clients handle all authentications
- Confusing API Gateway with data storage
