Protection must distinguish useful requests from unwanted ones
The gateway's role
An API Gateway applies shared rules before services: access checks, rate limiting and routing. In this lesson, the gateway checks for a valid key, then limits admitted traffic. Real authentication schemes are more complex; the switch is not a ready-made OAuth or JWT implementation.
Why a global limit does not solve everything
Of 1,000 accesses per second, only 700 are authorized. The backend handles 750. Sending all accesses uses capacity on outsiders and harms regular users. Simply limiting everything to 600 also discards useful requests. Check access first, then choose a limit.
Access denial and service error
Correctly rejecting an unauthorized request is expected behavior. Losing an authorized user's request fails the task. Error rate is therefore measured against the 700 useful requests, while blocked outsiders are counted separately. You cannot pass by rejecting almost all incoming traffic.
How to verify the policy
With the gateway added, enable key checks and compare backend traffic. After filtering, 700 requests/s remain. The limit must allow that volume. Also check that unauthorized requests cannot reach the application: adding a gateway alone does not enable the required policy.
Task
1,000 accesses/s: 700 with a valid key and 300 unauthorized. The backend handles 750 requests/s. Add a gateway, key checks and a rate limit.
Each second, 70% of requests are valid and 30% lack a key. The gateway checks keys first, then applies a proportional limit. Backend allocates 750 slots proportionally. This models admission, not full JWT/OAuth. Timeline and error rate include only useful requests; access rejections appear separately.
- Add an API Gateway and enable key validation.
- Set a limit that preserves useful traffic.
- Check useful request losses and the separate unauthorized-access counter.