agentleFS
zdanovichnickzdanovichnick/dotnet-pilot/skills/resilience/SKILL.md

resilience

Skill5 starsChanged 7 days agoMITView on GitHub

Polly v8 resilience patterns for .NET — retry, circuit breaker, timeout, hedging, and IHttpClientFactory integration using Microsoft.Extensions.Resilience.

8 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use observability and accessibility.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • OpenAISkill

    observability

    Vercel Observability expert guidance — Drains (logs, traces, speed insights, web analytics), Web Analytics, Speed Insights, runtime logs, custom events, OpenTelemetry integration, and monitoring dashboards. Use when instrumenting, debugging, or optimizing application performance and user experience on Vercel.

    Also in 3 projects that use this

  • ElasticSkill

    accessibility

    Accessibility guidance for Kibana. Use this skill when working with or reviewing EUI components, resolving a11y-related (@elastic/eui) ESLint issues, and ensuring proper use of ARIA attributes, focus management, keyboard interactions, and accessible naming conventions.

    Also in 3 projects that use this

The file

Files
SKILL.md

Resilience Patterns (Polly v8)

Reference for building fault-tolerant .NET services using Polly v8 and Microsoft.Extensions.Resilience.

Package Reference

<PackageReference Include="Microsoft.Extensions.Resilience" Version="9.*" />
<!-- For HTTP clients: -->
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.*" />

Breaking change from Polly v7: the Policy.Handle<>().Retry() API is gone. Use ResiliencePipelineBuilder exclusively.

Core Concepts

ConceptPurpose
ResiliencePipelineExecutes a delegate through a chain of strategies
ResiliencePipelineBuilderFluent builder — add strategies in order (outermost first)
ResiliencePipelineProvider<TKey>DI-resolved registry; resolve pipelines by key
ResilienceContextPer-execution metadata (cancellation token, properties)

Strategies execute in the order they are added. Outer strategies wrap inner ones — add timeout last to apply it per-attempt, or first to apply it to the whole pipeline.

References

Load only the file the task needs:

FileCovers
references/strategies.mdDI registration of pipelines; retry, circuit breaker, timeout, and hedging strategy options
references/httpclient.mdAddStandardResilienceHandler, a custom pipeline per client, consuming the named client
references/named-pipelines.mdResolving keyed pipelines from ResiliencePipelineProvider<TKey> for non-HTTP work

Recommended Pipeline Compositions

Use CaseStrategies (outer → inner)
Database queriesRetry (3x exponential) → Timeout (5s)
HTTP API callsTotal timeout (30s) → Retry (3x) → Circuit Breaker → Attempt timeout (10s)
Payment processingCircuit Breaker → Timeout (30s) — no retry (idempotency risk)
Read-heavy low-latencyHedging → Timeout
Background job stepRetry (5x linear) → Timeout (60s)

Gotchas

  • A timeout placed inside the retry is per attempt. The worst-case wall time is roughly attempts × attempt-timeout plus back-off delays. Add an outer timeout when callers need a hard cap (AddStandardResilienceHandler does this: 30s total, 10s per attempt).
  • Polly retry stacks with EF Core's EnableRetryOnFailure. EF's retrying execution strategy already retries transient SQL errors (SQL Server default: 6 retries). A Polly retry around the same SaveChangesAsync multiplies attempts and latency. Pick one retry layer for database calls. With EF's strategy enabled, a user-initiated transaction must run inside db.Database.CreateExecutionStrategy().ExecuteAsync(...).
  • Retrying a non-idempotent POST can duplicate the side effect. Retry it only with an idempotency key.

Do / Don't

DoDon't
Always pass CancellationToken to ExecuteAsyncLet the pipeline ignore cancellation
Add UseJitter = true to retry strategiesUse fixed delays (thundering herd)
Log retries with OnRetry callbackRetry silently — you lose observability
Set ShouldHandle to specific exceptionsHandle all exceptions with default predicate in payment flows
Place timeout after retry for per-attempt timeoutNest retry inside retry (doubles the attempt count unexpectedly)
Use AddStandardResilienceHandler for new HTTP clientsHand-roll retry loops around HttpClient
Use circuit breaker for downstream service callsUse circuit breaker for local in-memory operations

See Also

  • skills/caching/SKILL.md — HybridCache stampede protection reduces load, complementing circuit breakers
  • skills/error-handling/SKILL.md — BrokenCircuitException should surface as a Result.Failure at domain boundaries

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.