Problem, as an interviewer would state it: "Write a fetch wrapper that automatically retries a failed request with exponential backoff. What should actually count as 'failed' here — should it retry a 404?"
Examples:
await fetchWithRetry("/api/data"); // retries on real network failure or 5xx, not 4xx
Clarifying questions expected:
- Should client errors (4xx, like a genuine 404 or 401) be retried, or only server errors (5xx) and network failures?
- Is exponential backoff required specifically, or is a fixed delay between retries acceptable?
- Should the number of retries and the base delay be configurable?
Code / implementation expected: Yes — real, direct proof against real network endpoints: a genuine 404 returns immediately without retrying, while a genuinely unreachable domain retries the configured number of times before finally throwing.