Polly-Samples

November 4, 2023 ยท View on GitHub

Polly logo

This repository provides sample implementations of using the Polly library in a .NET application.

The intent of this project is to help newcomers kick-start the use of Polly within their own projects.

The samples demonstrate the policies in action, against faulting endpoints.

Projects

The solution contains three applications and one class library:

flowchart LR
    console{{PollyTestClientConsole}}
    wpf{{PollyTestClientWPF}}
    lib>PollyDemos]
    api[/PollyTestWebApi\]

    console -- uses --> lib
    wpf -- uses --> lib
    lib -- invokes --> api

Demos

General information

  • The demos run against an example 'faulting server'.
    • To simulate failure, the dummy server rejects more than 3 calls in any five-second period.
  • Be sure to read the <summary> at the top of each demo.
    • This explains the intent of that demo, and what resilience it adds to its handling of the calls to the 'faulting server'.
  • Sometimes the <summary> also highlights what this demo doesn't achieve, which is often picked up in the following demo.
  • Explore the demos in sequence for best understanding.

Sequence

#DescriptionLink
00No strategyCode
01Retry N timesCode
02Wait and retry N timesCode
03Wait and retry N times, N big enough to guarantee successCode
04Wait and retry foreverCode
05Wait and retry with exponential back-offCode
06Wait and retry nesting circuit breakerCode
07Wait and retry chaining with circuit breaker by using PipelineCode
08Fallback, Retry, and CircuitBreaker in a PipelineCode
09Fallback, Timeout, and Retry in a PipelineCode
10Without isolation: Faulting calls swamp resources,
also prevent good calls
Code
11With isolation: Faulting calls separated,
do not swamp resources, good calls still succeed
Code
12Hedging in latency modeCode
13Hedging in fallback mode: retry onlyCode
14Hedging in fallback mode: retry with fallbackCode
15Hedging in parallel modeCode
16Entity Framework with retry N timesCode

Want further information?

Slide decks

View the slides presented at NDC, DevIntersections and other conferences.

You are welcome to use and adapt this presentation for not-for-profit presentations of Polly to co-workers, user groups and similar, subject to the condition that references to the .NET Foundation, App-vNext and the individual members of the Polly team are retained.