Skip to main content

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.

RetryPolicy

Configurable retry logic with exponential backoff and custom predicates.

CircuitBreaker

Stop hammering unstable dependencies with automatic open/half-open/closed transitions.

RequestCache

Cache request results with TTL and stale-while-revalidate support.

RequestDeduplicator

Share a single in-flight promise across equivalent concurrent requests.

RateLimiter

Token bucket and sliding window limiters for outbound request control.

ErrorBoundary

Centralized error normalization, retries, and boundary utilities.

Quick example: combining primitives

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;
}
In day-to-day application code, many teams combine ApiClient, RetryPolicy, CircuitBreaker, RequestCache, and RateLimiter rather than using just one primitive.