Lab · Building blocks
API gateway
Three clients send requests through one gateway to three services. The gateway checks each API key, applies each client's rate limit, and routes by path. See what it stops, what a retry hides, and why one gateway is a single point of failure.
Try it
The lab is busy, so only some requests are drawn as dots, few enough to follow. The numbers still count every request.
- Mobile app — 8 requests/s — healthy — 4/10 tokens
- Partner — 6 requests/s — healthy — 10/10 tokens
- Bot — off — IDLE — no valid API key
- API gateway — 1 of 1 instance up — healthy — limit 10/s per client
- Users — 40 ms a call — healthy — 20 calls
- Orders — 80 ms a call — healthy — 13 calls
- Search — 120 ms a call — healthy — 20 calls
- Request
- Response
- Turned away (401, 429, 503) or error
- Retry
Numbers add up:53 sent = 0 stopped (401) + 0 stopped (429) + 52 answered + 0 failed + 0 no gateway + 1 in flightThe lab checks this sum as it runs, so a counting mistake would show here.
Controls
Follow a request
Pause to pick a request that is on screen.
Each client
| Client | Sent | 401 | 429 | 503 | OK | Failed |
|---|---|---|---|---|---|---|
| Mobile app | 33 | 0 | 0 | 0 | 32 | 0 |
| Partner | 20 | 0 | 0 | 0 | 20 | 0 |
| Bot | 0 | 0 | 0 | 0 | 0 | 0 |
401: no valid API key. 429: over the limit. The gateway stopped both. 503: the load balancer found no running gateway to take the request. Only OK and Failed requests reached a service.
Show data table
| Time | Answered | Stopped at the gateway | No gateway (503) | Failed after routing |
|---|---|---|---|---|
| 1s | 12 | 0 | 0 | 0 |
| 1s | 14 | 0 | 0 | 0 |
| 2s | 18 | 0 | 0 | 0 |
| 2s | 16.5 | 0 | 0 | 0 |
| 3s | 17.5 | 0 | 0 | 0 |
| 3s | 19 | 0 | 0 | 0 |
What just happened
- 0.0sInfo: Each client with a valid API key may send 10 requests a second.
What this model simplifies
- Time is slowed so you can watch each request. Service times are fixed and illustrative: Users 40 ms, Orders 80 ms, Search 120 ms.
- Every call here reads data, so a retry is safe. A gateway should not retry a write unless it carries an idempotency key.
- The gateway checks a token and a limit in 5 ms and never runs short of capacity itself. A real gateway can become a bottleneck.
- A real gateway also ends TLS, rewrites requests and writes logs. Those are left out because they change no numbers here.
- Real gateways also limit by IP address before the key check, so a flood of bad requests still costs them a little work.
- A restarted instance takes traffic at once. A real load balancer waits for a passing health check, and often answers 502 for a crashed instance.
- The load balancer in front of the gateway instances is not drawn, and it never fails.