> ## Documentation Index
> Fetch the complete documentation index at: https://bytekit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Resilience

> Overview of ByteKit resilience primitives — retries, circuit breaking, caching, deduplication, rate limiting, and error boundaries.

## What this group covers

Use these modules when an integration can fail, slow down, duplicate itself, or overwhelm a remote service. Each module targets one concern; combine them for production-grade resilience.

<CardGroup cols={2}>
  <Card title="RetryPolicy" icon="rotate" href="/api-reference/retry-policy">
    Configurable retry logic with exponential backoff and custom predicates.
  </Card>

  <Card title="CircuitBreaker" icon="toggle-on" href="/api-reference/circuit-breaker">
    Stop hammering unstable dependencies with automatic open/half-open/closed transitions.
  </Card>

  <Card title="RequestCache" icon="box-archive" href="/api-reference/request-cache">
    Cache request results with TTL and stale-while-revalidate support.
  </Card>

  <Card title="RequestDeduplicator" icon="clone" href="/api-reference/request-deduplicator">
    Share a single in-flight promise across equivalent concurrent requests.
  </Card>

  <Card title="RateLimiter" icon="gauge-high" href="/api-reference/rate-limiter">
    Token bucket and sliding window limiters for outbound request control.
  </Card>

  <Card title="ErrorBoundary" icon="shield-halved" href="/api-reference/error-boundary">
    Centralized error normalization, retries, and boundary utilities.
  </Card>
</CardGroup>

## Quick example: combining primitives

```ts theme={null}
import { ApiClient } from "bytekit/api-client";
import { RequestCache, RateLimiter } from "bytekit";

const api = new ApiClient({
  baseUrl: "https://api.example.com",
  retryPolicy: { maxAttempts: 3, initialDelayMs: 200 },
  circuitBreaker: { failureThreshold: 5, timeoutMs: 30_000 },
});

const cache = new RequestCache({ ttl: 60_000, staleWhileRevalidate: 15_000 });
const limiter = new RateLimiter({ maxRequests: 20, windowMs: 60_000 });

async function getCatalog() {
  const cached = cache.get("/catalog");
  if (cached) return cached;

  await limiter.waitForAllowance("/catalog");
  const fresh = await api.get("/catalog");
  cache.set("/catalog", fresh);
  return fresh;
}
```

<Tip>
  In day-to-day application code, many teams combine `ApiClient`, `RetryPolicy`, `CircuitBreaker`, `RequestCache`, and `RateLimiter` rather than using just one primitive.
</Tip>
