Ask Claude to Add Retry Logic with Exponential Backoff
A production API integration without retry logic is a support ticket waiting to happen. The problem is, writing it correctly — with jitter, header inspection, and circuit breaking — is tedious. Claude handles all of it.
Add retry logic with exponential backoff to the fetchUserData function
in src/api/users.ts. Retry up to 3 times on 429 and 5xx responses.
Use 500ms as the initial delay, double it each attempt, and add random
jitter to prevent thundering herd problems.
Claude covers the subtle bits you'd likely miss on a first pass: respecting Retry-After response headers, distinguishing retryable errors (429, 503) from non-retryable ones (400, 401, 404), and adding enough logging to diagnose retry storms in production.
// Ask for a reusable generic wrapper
Write a generic retry<T>(fn: () => Promise<T>, options: RetryOptions) utility
in src/utils/retry.ts. Include:
- Configurable max retries and base delay
- Exponential backoff with jitter
- An optional shouldRetry predicate for custom logic
- A circuit breaker that opens after N consecutive failures
You can also ask Claude to wrap an entire service class rather than individual functions, so the retry behaviour is applied consistently without repeating yourself.
Resilient API integrations aren't optional in production — Claude makes them trivial to add.
Log in to leave a comment.
The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.
The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.
Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.