Route Behavior

Rate Limit Simulation

Most real APIs throttle you eventually, and the code that handles it — backoff, retry, a queue that drains slower — is some of the least-tested code in any client. Rate limit simulation makes a route start returning 429 after a set number of requests, so that path actually runs.

Configuring it

In the route's Advanced section, set Requests and the window in seconds. Once that many requests arrive inside the window, every further request to that route gets a 429 until the window rolls over. Setting requests to 0 turns it off, which is the default.

The counter is per route, not per mock: exhausting GET /orders doesn't throttle POST /orders. It's also shared across everyone calling that route, not per client IP — a mock endpoint is usually being hit by one test suite or one developer, and a global counter is what makes "the 3rd request fails" reproducible.

What a throttled request returns

HTTP/1.1 429 Too Many Requests
Retry-After: 18
X-RateLimit-Limit: 2
X-RateLimit-Remaining: 0

{"error": "rate_limited", "detail": "Simulated rate limit exceeded."}

Retry-After counts the seconds left in the current window, so a client that honors it will wait exactly long enough — which is the behavior worth testing.

Why not just use chaos injection?

Chaos injection can also return a 429, but it does so at random. That's the wrong tool here: a backoff test needs to know which request fails. Rate limiting is deterministic — with a limit of 2, the third request fails, every run, which is something a test can assert on.

The two compose, though. A route with both set can be flaky and throttled, which is a realistic picture of an upstream having a bad day.

Windows are fixed, not sliding

The window is a fixed bucket: it starts at a wall-clock boundary and resets, rather than sliding continuously with each request. So a burst spanning a reset can briefly allow up to twice the limit. This matches how a lot of real API gateways behave, and it keeps the check to a single Redis operation on the request path.

Limits

The window can be anywhere from 1 second to 24 hours. The counter lives in Redis with the window's own lifetime, so nothing needs cleaning up — and if the limiter's backend is ever unavailable, the request is allowed through rather than failing, the same policy MockBase's own platform limits use.