REST API
Retry with Backoff
RetryErrorRequestHard
What you will learn
- Retry only idempotent methods (GET, PUT, DELETE) โ retrying POST may double-charge
- Use exponential backoff with jitter โ synchronized retries create thundering herds
- Cap retries and fail loud โ infinite retries hide upstream outages from monitoring
Description
Implement exponential backoff for transient failures.
Test Scenario
async function fetchWithRetry(url, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
const response = await request.get(url);
if (response.status() !== 503) return response;
await sleep(Math.pow(2, i) * 1000);
}
throw new Error('Max retries exceeded');
}Endpoint
/api/v1/retryTesting Tips
- โขRetry on 503 Service Unavailable
- โขUse exponential backoff (1s, 2s, 4s)
- โขSet max retry limit
// Playwright API Testing - RESTimport { test, expect } from '@playwright/test';test('REST API request', async ({ request }) => {const response = await request.get('/api/v1/resource');expect(response.ok()).toBeTruthy();expect(response.status()).toBe(200);const data = await response.json();expect(data).toBeDefined();});
Challenge ID: rest-retry-pattern
2 frameworks available
API Playground
Send requests and inspect responses
Endpoint: /api/v1/retry
Press Enter to send