Introduction
Kevlar is fast, allocation-conscious resilience for .NET. Retries, circuit breakers, timeouts, rate limiting, concurrency limits, hedging and fallbacks — composed through one fluent shield API.
using Kevlar;
var shield = Shield
.Timeout(TimeSpan.FromSeconds(30)) // total budget for the whole operation
.Retry(3) // exponential backoff + jitter, out of the box
.CircuitBreaker(5, breakDuration: TimeSpan.FromSeconds(30));
var user = await shield.ExecuteAsync(ct => LoadUserAsync(id, ct), cancellationToken);
Build a shield once, reuse it everywhere. Shields are immutable and thread-safe.
Why Kevlar?
- Intuitive first.
Shield.When<TimeoutException>().Retry(3)reads like what it does. No context pooling ceremony, no predicate-builder classes, no options objects for the simple cases — and full options objects when you want them. - Fast. Outcomes flow between pipeline layers as structs instead of thrown exceptions; contexts are pooled internally; state-passing overloads eliminate closures;
ValueTaskend to end. - Production defaults.
Shield.Retry(3)gives you exponential backoff with jitter capped at 30s — the thing you'd have configured anyway. - Hard to hold wrong.
TaskandValueTaskdelegates both flow straight in; impossible chain orders throw at build time with a fix in the message; theKevlar.Analyzerspackage flags cancellation and pipeline hazards at compile time. - Observable out of the box. Every shield describes itself (
shield.ToString()prints the whole pipeline) and publishes metrics through a built-inMeter— no telemetry package, no setup. - Composable. Shields merge with
WrapandCompose, chain fluently, and stateful strategies (breakers, limiters) intentionally share their state wherever the same shield instance is reused. - Broad reach.
netstandard2.0(covers .NET Framework 4.6.2+) andnet10.0targets.
Packages
| Package | Purpose |
|---|---|
Kevlar | The core: all strategies |
Kevlar.Chaos | Opt-in latency, fault, typed outcome and custom behavior injection |
Kevlar.Extensions.DependencyInjection | Named shields + IKevlarRegistry for Microsoft DI |
Kevlar.Extensions.Http | HttpClientFactory integration, transient-fault handling, Retry-After support |
Kevlar.Extensions.RateLimiting | System.Threading.RateLimiting and custom lease-acquisition adapters |
Kevlar.Analyzers | Roslyn analyzers that catch resilience mistakes at compile time |
Where to next?
- Getting Started — install and build your first shield in five minutes.
- Strategies — every resilience behaviour in detail.
- Coming from Polly? — a 1:1 translation table.