| Users / Traffic | What Changes? | Gateway Load | Latency Impact | Security & Features |
|---|---|---|---|---|
| 100 users | Basic routing, simple auth | Single gateway instance handles traffic | Low latency, minimal overhead | Basic rate limiting, logging |
| 10,000 users | Increased requests, more auth checks | Multiple gateway instances behind load balancer | Latency slightly increases due to processing | Advanced rate limiting, caching enabled |
| 1,000,000 users | High concurrency, complex routing rules | Horizontal scaling of gateways, caching layers added | Latency managed with caching and optimized configs | Security policies, JWT validation, throttling |
| 100,000,000 users | Massive traffic, global distribution | Multi-region gateway clusters, CDN integration | Latency minimized via edge caching and CDNs | WAF, DDoS protection, advanced analytics |
Popular gateways (Kong, AWS API Gateway, Nginx) in Microservices - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
The first bottleneck is usually the API gateway server CPU and memory. As traffic grows, the gateway must process authentication, routing, rate limiting, and logging for every request. This processing can overwhelm a single instance, causing increased latency and dropped requests.
- Horizontal Scaling: Add more gateway instances behind a load balancer to distribute traffic.
- Caching: Use response caching to reduce repeated processing for the same requests.
- Rate Limiting: Protect backend services by limiting requests per user or IP.
- Offload SSL/TLS: Terminate SSL at load balancer or CDN to reduce gateway CPU load.
- Use CDN: For static content and some API responses, reduce load on gateways.
- Sharding: Route traffic based on user segments or regions to different gateway clusters.
- At 1 million users, assuming 1 request per second each, gateways handle ~1 million RPS.
- A single gateway instance handles ~3000 RPS; need ~350 instances for 1M RPS.
- Storage for logs: 1M RPS * 100 bytes/log * 3600 seconds = ~360 GB/hour.
- Bandwidth: 1M RPS * 1 KB/request = ~1 GB/s (~8 Gbps network).
- Costs rise with instances, bandwidth, and storage for logs and metrics.
Start by identifying the main components and their limits. Discuss how traffic growth affects each part, especially the gateway. Then propose clear scaling steps: horizontal scaling, caching, and offloading work. Always mention trade-offs like cost and complexity.
Your API gateway handles 3000 requests per second. Traffic grows 10x to 30,000 RPS. What do you do first?
Answer: Add more gateway instances behind a load balancer to distribute the load horizontally. This prevents CPU and memory overload on a single instance and maintains low latency.
Practice
Solution
Step 1: Understand the role of API gateways
API gateways act as a control point for requests between clients and microservices, managing traffic and security.Step 2: Compare options with gateway functions
Storing data, running business logic, or replacing databases are not typical gateway roles.Final Answer:
Control and protect communication between services -> Option AQuick Check:
Gateway role = Control communication [OK]
- Confusing gateways with databases
- Thinking gateways run business logic
- Assuming gateways store data
Solution
Step 1: Review Kong route syntax
Kong routes use a list with keys: name, paths (as a list), and service.Step 2: Identify correct YAML structure
routes:\n - name: example-route\n paths: ['/example']\n service: example-service correctly uses a list with dash, keys with colons, and paths as a list.Final Answer:
routes:\n - name: example-route\n paths: ['/example']\n service: example-service -> Option BQuick Check:
Kong route syntax = routes:\n - name: example-route\n paths: ['/example']\n service: example-service [OK]
- Missing colon after keys
- Using string instead of list for paths
- Incorrect indentation or dash placement
/api/users?
location /api/ {
proxy_pass http://backend-service/;
}Solution
Step 1: Understand Nginx proxy_pass behavior with trailing slash
When proxy_pass URL ends with a slash, Nginx replaces the matching location prefix with the proxy URL path.Step 2: Apply to given example
Location prefix is /api/, proxy_pass is http://backend-service/, so /api/ is replaced by /, forwarding /users to backend-service.Final Answer:
The request is forwarded to http://backend-service/users -> Option AQuick Check:
Trailing slash in proxy_pass removes location prefix [OK]
- Assuming full path is appended
- Confusing proxy_pass with or without trailing slash
- Thinking request is blocked or 404
/items and a GET method, but requests to /items return 403 Forbidden. What is the most likely cause?Solution
Step 1: Check AWS API Gateway method deployment
Methods must be deployed and enabled in the stage to accept requests.Step 2: Understand 403 Forbidden meaning in API Gateway
403 often means method exists but is not authorized or deployed, not backend URL or IP block.Final Answer:
The GET method is not deployed or enabled in the stage -> Option CQuick Check:
403 = method not deployed/enabled [OK]
- Assuming backend URL causes 403
- Thinking API Gateway disallows GET
- Blaming client IP blocking without evidence
serviceA at /serviceA and serviceB at /serviceB. Which configuration approach ensures correct routing and avoids path conflicts?Solution
Step 1: Understand routing by path in Kong
Kong routes requests based on path prefixes to the correct service.Step 2: Avoid path conflicts by using distinct paths
Separate paths like '/serviceA' and '/serviceB' ensure requests go to the right service without overlap.Final Answer:
Create two routes with paths ['/serviceA'] and ['/serviceB'], each linked to their respective services -> Option DQuick Check:
Distinct paths = correct routing [OK]
- Using same path for multiple services
- Relying on backend to route without gateway paths
- Using root path for all services
