Resilience, Retries & Circuit Breaker

Configure retries and the circuit breaker. The linked guides cover concurrency, deduplication, and offline replay.


1. Retrying Transient Failures

Retries are opt-in. The attempts parameter specifies how many retry attempts to make after the initial request. Full randomized jitter prevents the thundering herd problem:

retry.ts
typescript
import { createClient } from 'react-native-fetch-client';

const api = createClient({
  baseURL: 'https://api.example.com',
  retry: {
    attempts: 3,
    backoff: 'exponential',
    delay: 500,
    maxDelay: 10_000,
    jitter: true,
  },
});

const response = await api.get('/catalog');

2. Circuit Breaker Pattern

The circuit breaker tracks failures for the configured client instance. When the threshold is reached, it opens and rejects subsequent requests until its reset interval allows a probe:

typescript
import { createClient } from 'react-native-fetch-client';

const api = createClient({
  baseURL: 'https://api.example.com',
  circuitBreaker: {
    enabled: true,
    failureThreshold: 5,
    resetTimeoutMs: 30_000, // 30s cooling period
  },
});

3. Deduplication & Concurrency

Coalesce parallel GET requests and throttle maximum concurrent network flights:

typescript
import { createClient } from 'react-native-fetch-client';

const api = createClient({
  dedup: { enabled: true },
  maxConcurrentRequests: 4,
});

const [first, second] = await Promise.all([
  api.get('/users/me'),
  api.get('/users/me'),
]);
Offline request queue
For queue storage, replay behavior, and idempotency details, see the offline queue guide.