ZeroAlloc.Resilience
3.3.5
dotnet add package ZeroAlloc.Resilience --version 3.3.5
NuGet\Install-Package ZeroAlloc.Resilience -Version 3.3.5
<PackageReference Include="ZeroAlloc.Resilience" Version="3.3.5" />
<PackageVersion Include="ZeroAlloc.Resilience" Version="3.3.5" />
<PackageReference Include="ZeroAlloc.Resilience" />
paket add ZeroAlloc.Resilience --version 3.3.5
#r "nuget: ZeroAlloc.Resilience, 3.3.5"
#:package ZeroAlloc.Resilience@3.3.5
#addin nuget:?package=ZeroAlloc.Resilience&version=3.3.5
#tool nuget:?package=ZeroAlloc.Resilience&version=3.3.5
ZeroAlloc.Resilience
Retry, timeout, rate limiting and circuit breaking for .NET, declared as attributes on an interface and compiled into a proxy: a source-generated alternative to Polly with no allocation on the happy path.
Why ZeroAlloc.Resilience
- 0 B per successful call through
[Retry]and[CircuitBreaker], asserted by tests on every run. Polly v8 allocates a 64 BResilienceContextper call. - 14.7× and 15.0× faster than Polly v8 on the retry and circuit-breaker happy paths, and 5.9× faster with all four policies stacked, measured in the same run.
- Works under NativeAOT and trimming. The proxy is plain generated code with no reflection, published as a NativeAOT app in CI.
- Mistakes surface at compile time. A misspelled fallback, an invalid attribute value or a timeout on a method without a
CancellationTokenis a compiler diagnostic.
Install
dotnet add package ZeroAlloc.Resilience
Quick start
using Microsoft.Extensions.DependencyInjection;
using ZeroAlloc.Resilience;
var services = new ServiceCollection();
services.AddWeatherClientResilience<FlakyWeatherClient>(); // generated: registers the proxy
var client = services.BuildServiceProvider().GetRequiredService<IWeatherClient>();
Console.WriteLine(await client.GetForecastAsync("Amsterdam", CancellationToken.None));
// Amsterdam: sunny, after 3 attempts
[Retry(MaxAttempts = 3, BackoffMs = 100, Jitter = true)]
[Timeout(Ms = 5_000)]
[CircuitBreaker(MaxFailures = 5, ResetMs = 30_000)]
public interface IWeatherClient
{
ValueTask<string> GetForecastAsync(string city, CancellationToken ct);
}
public sealed class FlakyWeatherClient : IWeatherClient
{
private int _calls;
public ValueTask<string> GetForecastAsync(string city, CancellationToken ct)
=> ++_calls < 3
? throw new HttpRequestException($"attempt {_calls} failed")
: ValueTask.FromResult($"{city}: sunny, after {_calls} attempts");
}
The first two calls throw, the proxy retries, and the caller only sees the result. Callers inject IWeatherClient as usual.
What you get
- Retry with exponential backoff, jitter, a per-attempt timeout and a cap on the delay.
- Timeout over the whole operation, retries and backoff included.
- Rate limiting with a lock-free token bucket, shared per interface or per proxy.
- Circuit breaker with half-open probing and an optional fallback method.
- A fixed, predictable order: rate limit, circuit breaker, timeout, retry, whatever order you write the attributes in.
- Exceptions or Results: return a ZeroAlloc.Results
Result<T>and policy failures come back as a failure instead of a throw. - Result-aware retry: retry only the failures you call transient, and honour
Retry-Afterhints. - Per-method overrides of the interface-level policies, for example one attempt for a non-idempotent POST.
- One-line DI registration through a generated
Add{Service}Resilience<TImpl>()extension. - Compile-time diagnostics ZR0001–ZR0013: the full list. Every attribute property: attribute reference.
Performance
Against Polly.Core 8.8.0 on .NET 10.0.13, measured 2026-10-15. Allocations are exact; speed is a same-run ratio, because the benchmark host is a shared VM.
| Operation | ZA vs Polly | Polly alloc | ZA alloc |
|---|---|---|---|
| Retry, happy path | 14.7× faster | 64 B | 0 B |
| CircuitBreaker, closed | 15.0× faster | 64 B | 0 B |
| All-policies stacked, happy path | 5.9× faster | 104 B | 144 B |
With all policies stacked, the 144 B is the linked CancellationTokenSource and timer that [Timeout] needs; without [Timeout] the proxy allocates nothing. Polly walks a delegate chain per call; ZA emits one method with the policy checks inline. Failure paths, an open circuit and the full method: docs/performance.md.
Learn more
- Documentation: resilience.zeroalloc.net
- Getting started, execution order, Result return types and migrating to 3.0
- Related packages: ZeroAlloc.Rest for source-generated HTTP clients, ZeroAlloc.Cache for caching proxies, ZeroAlloc.Telemetry for tracing and metrics proxies
- Contributing: issues and pull requests are welcome on GitHub
- License: MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- ZeroAlloc.Results (>= 1.2.2)
- ZeroAlloc.StateMachine (>= 1.5.3)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- ZeroAlloc.Results (>= 1.2.2)
- ZeroAlloc.StateMachine (>= 1.5.3)
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- ZeroAlloc.Results (>= 1.2.2)
- ZeroAlloc.StateMachine (>= 1.5.3)
NuGet packages (12)
Showing the top 5 NuGet packages that depend on ZeroAlloc.Resilience:
| Package | Downloads |
|---|---|
|
ZeroAlloc.Scheduling
Source-generated zero-allocation background job scheduling for .NET. |
|
|
ZeroAlloc.Outbox
Source-generated transactional outbox for .NET. |
|
|
ZeroAlloc.Rest.Resilience
Wires ZeroAlloc.Rest clients through ZeroAlloc.Resilience proxies. Annotate a [ZeroAllocRestClient] interface with [Retry]/[Timeout]/[CircuitBreaker]; call AddRestResilience to register the resilience-wrapped HTTP client. |
|
|
ZeroAlloc.Scheduling.Resilience
ZeroAlloc.Resilience bridge for ZeroAlloc.Scheduling — wraps IJobTypeExecutor implementations in a Resilience-generated proxy. |
|
|
AI.Sentinel
Security monitoring middleware for IChatClient — prompt injection, hallucination, and operational anomaly detection with an intervention engine. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.3.5 | 5,488 | 10/16/2026 |
| 3.3.4 | 2,464 | 10/15/2026 |
| 3.3.3 | 4,501 | 10/12/2026 |
| 3.3.2 | 4,702 | 10/11/2026 |
| 3.3.1 | 13,776 | 9/30/2026 |
| 3.3.0 | 8,595 | 9/27/2026 |
| 3.2.0 | 2,616 | 9/26/2026 |
| 3.1.0 | 3,517 | 9/25/2026 |
| 3.0.0 | 111 | 9/25/2026 |
| 2.0.1 | 938 | 9/25/2026 |
| 2.0.0 | 661 | 9/24/2026 |
| 1.3.8 | 123 | 9/24/2026 |
| 1.3.7 | 106 | 9/24/2026 |
| 1.3.6 | 147 | 9/24/2026 |
| 1.3.5 | 109 | 9/24/2026 |
| 1.3.4 | 1,454 | 9/20/2026 |
| 1.3.3 | 238 | 9/20/2026 |
| 1.3.2 | 5,864 | 9/19/2026 |
| 1.3.1 | 3,646 | 8/12/2026 |
| 1.3.0 | 6,164 | 5/13/2026 |