QA Interview Hub · Knowledge base · Quizzes · Українська

API › Performance and reliability

429, 503, Retry-After and the circuit breaker

429 means this client exceeded a limit, and 503 means the service temporarily cannot handle the request. Both may carry Retry-After with seconds or a date, and a client does not retry earlier and adds jitter. A circuit breaker opens after a threshold of failures and immediately returns an error or fallback, then closes again through trial requests; all three states are tested, including recovery.

API · Fault tolerance

A service returned 429 and the client retried at once. Why did it get worse?

A frontend shows search. The server returns 429 because the client exceeded a limit. The client repeats the request ten more times without pauses, the limit does not reset, and the user sees a spinner. Meanwhile the search dependency is down, and every request waits out its five-second timeout. This lesson is about how a server says "wait" (Retry-After), how a service protects itself from a chain failure (a circuit breaker) and what a tester checks.

How it works

429 Too Many Requests (RFC 6585) means this particular client exceeded a limit. 503 Service Unavailable (RFC 9110) means the service temporarily cannot handle the request: overload, a deploy, a dependency is down. The difference matters for diagnosis: 429 is fixed in the client, 503 points to the server's state. Both may carry a Retry-After header: either a number of seconds or an HTTP date.

HTTP/1.1 429 Too Many Requests
Retry-After: 30
Content-Type: application/problem+json

{ "type": "about:blank", "title": "Too Many Requests", "status": 429 }

HTTP/1.1 503 Service Unavailable
Retry-After: Wed, 11 Nov 2026 07:28:00 GMT

A correct client does not repeat earlier than told and still adds jitter, because many clients received the same time. Limits often have extra headers such as X-RateLimit-Remaining, but they are not finally standardised, so they are checked only against the documentation of a specific API.

A circuit breaker solves a different problem. When a dependency is unavailable, every call to it waits the full timeout, threads pile up, and little by little the service itself goes down. The breaker counts failures and after a threshold "opens": the next calls return an error or a fallback at once, without waiting. After a while it lets a few trial requests through and, if they succeed, closes again.

closed    : calls go through, failures are counted
   | failure rate above the threshold
open      : calls fail at once (error or fallback), no waiting
   | after the cool-down
half-open : a few trial calls
   | success -> closed      failure -> open

Without a breaker and with one

Typical

Without a breaker

Every request waits the dependency's 5 s timeout. Threads ran out, and the service is slow even for requests that do not need the dependency.

Better

With a breaker

After a series of failures, calls to the dependency instantly return an error or a fallback. The rest of the functionality works, and recovery is noticed without manual action.

Figure 1. A breaker does not heal the dependency. It stops its failure from taking other parts of the system down.

Example: what to check on a limit

The test reaches the documented limit, checks the header, waits and makes sure requests pass again:

test('limit: 429 carries a valid Retry-After and recovers', async ({ request }) => {
  test.setTimeout(120_000); // Retry-After may be up to 60 s
  let res = await request.get('/v1/search?q=a');
  for (let i = 0; i < 200 && res.status() !== 429; i++) {
    res = await request.get('/v1/search?q=a'); // hit the documented limit
  }
  expect(res.status()).toBe(429);

  const wait = Number(res.headers()['retry-after']);
  expect(wait).toBeGreaterThan(0);
  expect(wait).toBeLessThanOrEqual(60);

  await new Promise((r) => setTimeout(r, wait * 1000));
  expect((await request.get('/v1/search?q=a')).status()).toBe(200);
});

A resilience scenario for the breaker is different: slow down or switch off the dependency (with a stub or a chaos tool) and check three things. The main service answers quickly with a controlled error or a fallback instead of hanging until the timeout. The metrics show the move to the open state. When the dependency returns, everything recovers without manual intervention.

Limits and alternatives

  • How a limit is counted depends on the algorithm (fixed window, sliding window, token bucket): at a window boundary a client may get twice the requests. That is the algorithm's behaviour, not necessarily a bug, and the documentation describes it.
  • A limit can apply per API key, user or IP. The test must use the same identifier and not mix counters.
  • A breaker with a fallback hides the failure from the user: that is useful, but you need metrics and an alert, otherwise nobody learns about the problem.
  • Next to it there are bulkheads (separate resource pools so one dependency does not exhaust all of them) and a client-side rate limiter. They complement the breaker rather than replace it.

Common mistakes

  • Ignoring Retry-After. The client retries earlier and stays in 429 longer.
  • Retrying 429 without an attempt limit. An endless loop never ends if the limit is permanent.
  • Mixing up 429 and 503. The first is about the client, the second about the service, and the reactions differ: slow down or wait for recovery.
  • Testing the breaker only when the dependency fails, not when it returns. Half of the defects are in recovery: the breaker never closes again.

Check yourself

The server returns 429 without Retry-After. What does the client do and what does the tester check?

Answer

The client falls back to its own backoff with jitter. The tester checks the documentation: if the header is promised, its absence is a defect. If not, they check that the client does not retry endlessly and shows a clear message.

The dependency recovered, but five minutes later the service still returns the fallback. What can be wrong with the breaker?

Answer

It does not move from open to half-open, or it does not close after successful trial requests. This is checked precisely on recovery: bring the dependency back, wait out the cool-down and require that responses become real again without a restart.

In an interview. Junior: On 429 and 503 I check Retry-After and that the client does not retry earlier. A circuit breaker stops calling the dependency after a series of failures and quickly returns an error or a fallback. Middle/Senior: I test all three states: open after a series of failures, half-open after a pause and closing again after successful probes. Separately I check that the limit triggers at the right threshold, that the client adds jitter and that a breaker trip is visible in metrics and alerts.

More articles in this chapter