Recipe cookbook¶
Copy-pasteable, API-accurate recipes for common resilience scenarios. Every
snippet uses the real public API of
github.com/sanskarpan/Rate-Limiter-Circuit-Breaker.
Migrating from another library? Start with the migration guide.
Rate limiting¶
- Rate limit per IP (Gin, chi, echo, Fiber) — drop-in middleware for the four supported HTTP frameworks.
- Per-tenant / per-API-key quotas — keyed limiters plus
a composite
ANDfor stacked global + per-tenant tiers. - Cost / weight-based limiting — charge expensive
endpoints more tokens with
WithCost/AllowN. - Distributed rate limit with Redis + fail-open — fleet-wide limits, server-time clock-skew mitigation, graceful degradation.
Resilience¶
- Protect a flaky downstream — circuit breaker + retry (with a retry budget) + hedge/fallback via the pipeline.
- Adaptive concurrency + load shedding — self-tuning concurrency limits and CoDel-style shedding under overload.
Observability¶
- Prometheus metrics + OpenTelemetry tracing —
wire the
metric.Recorderadapter and OTel spans.