liveBook · Manning

Retry

As explained in .NET in Action, Second Edition

A retry policy is a resilience rule that automatically repeats an operation after qualifying failures.

A retry policy automatically repeats an operation after qualifying failures. Use retries for transient faults, such as temporary database unavailability, network failures, timeouts, or selected HTTP 500-level responses—not for every failure indiscriminately. section 11.0 section 11.3

EF Core execution strategies provide database-specific automatic retries, but transactions require special handling. A lost connection during commit can leave the outcome uncertain, so verify the transaction when possible or deliberately retry the complete transaction. section 11.2.2 section 11.4

Production retry implementations should:

  • Retry only failures classified as transient or otherwise safe to repeat. section 11.2.2
  • Use delay and back-off rather than issuing immediate repeated requests. section 11.3.2
  • Test policies by simulating failures, including invalid HTTP responses. section 11.3 section 11.4

Retrying an HTTP request with Polly

Register a Polly policy on an HttpClient, handle transient HTTP errors, and wait between six attempts using an exponentially increasing delay. Customize the policy when a specific response, such as 429 Too Many Requests, also requires a retry.

How .NET in Action, Second Edition covers it

How deep it goes
Explains transient classification, exponential back-off, transaction uncertainty, and policy registration, but does not fully develop Polly’s broader strategies.
Examples
Uses EF Core money transfers, SQL Server configuration, mocked XKCD HTTP responses, Polly handlers, and exponential delays.
What it assumes
Assumes familiarity with C#, asynchronous operations, EF Core, dependency injection, HTTP clients, and database transactions.
What you can do after
Apply it via EF Core execution strategies and Polly policies, including transaction verification and tested HTTP back-off.
How it connects
Connects retries with transient faults, database transactions, EF Core execution strategies, HTTP clients, Polly, and circuit breakers.

Also explained in

Compare how 21 books explain retry →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.