ThisCalculator

Everyday

.NET 10 HTTP Resilience, Safe Retries and Tracing

Updated · Standard formula, shown below

.NET 10 provides HTTP resilience through the standard HTTP resilience extensions, which combine retry, timeout, circuit-breaker, and related strategies for outgoing requests. Configure them on an HttpClient through dependency injection, make retries conditional on the request being safe to repeat, and enrich distributed traces with useful—but non-sensitive—context.

What HTTP resilience means in .NET 10

An HTTP call can fail because of a brief network interruption, an overloaded service, or a slow response. Resilience policies help an application handle some temporary failures without immediately failing its own operation or adding unlimited pressure to the service. They do not make a remote dependency infallible, and they cannot tell whether a request that timed out was already processed by the server.

In .NET 10, the usual approach for dependency-injected clients is the HTTP resilience integration in Microsoft.Extensions.Http.Resilience. Its handler pipeline is built on Polly resilience components and integrates with IHttpClientFactory. The standard resilience handler combines several strategies, including rate limiting, total and per-attempt timeouts, retries, a circuit breaker, and a timeout associated with the circuit breaker. Exact defaults and available options should be checked against the package version in use; applications should set and test behavior deliberately rather than relying on assumed timing.

Configure a resilient HttpClient

Install the resilience package that matches the application’s dependency setup, then register a named or typed client. For example:

builder.Services.AddHttpClient<CatalogClient>(client =>
{
    client.BaseAddress = new Uri("https://api.example.test/");
})
.AddStandardResilienceHandler();

The example shows the registration pattern, not a production endpoint. A typed client should receive its configured HttpClient through dependency injection. For a particular downstream service, configure a dedicated client rather than applying one policy indiscriminately to every outgoing request.

The standard handler is a useful starting point, but its strategies can be customized. Avoid stacking multiple retry handlers or adding a second resilience pipeline without understanding their combined effects: nested retries can multiply attempts, while overlapping timeouts and breakers can make failures difficult to interpret. Keep policy configuration close to the client it protects and document its expected behavior.

Safe retries and idempotency

A retry sends a request again after a qualifying failure. That is safe only when repeating the operation is acceptable. HTTP defines methods such as GET, PUT, and DELETE as idempotent in their intended effect, whereas POST is not generally idempotent. Real APIs may impose additional rules, so the API contract matters more than the method name alone.

Consider a payment-like operation: the client sends a POST, the server commits it, but the response is lost. A retry without safeguards could create a duplicate. If the service supports idempotency keys, send the same key for every attempt of the same logical operation and follow that service’s documented retention and conflict rules. A new key for each retry would defeat the protection. For non-idempotent operations without server-side deduplication, automatic retries may be inappropriate.

Retry only failures likely to be transient. A resilience pipeline can consider transport exceptions and selected status codes, but should not blindly retry validation errors, authentication failures, or every server response. Respect a server’s Retry-After guidance when supported by the configured strategy. Use a bounded attempt count and backoff, often with jitter, so many clients do not synchronize into repeated bursts. A retry budget should fit inside the caller’s overall deadline.

Circuit breakers, timeouts, and load

A circuit breaker watches failures and, after its configured threshold is reached, temporarily rejects calls rather than continuing to send traffic to an unhealthy dependency. After a break period, it permits limited probing so the application can discover whether the service has recovered. It is not a retry mechanism: the breaker limits calls; retries repeat selected calls.

Timeouts bound how long the application waits. A per-attempt timeout limits each individual request, while an overall timeout limits the complete operation, including retries and delays. The overall deadline should be compatible with the user-facing request or background job deadline. If the outer request has already been canceled, continuing retries wastes resources.

These safeguards interact. A slow dependency can consume connection capacity even when retries are bounded; a very short timeout can misclassify normal latency as failure; an overly sensitive breaker can reject traffic during a brief fluctuation. Measure latency and failure rates, set limits from service objectives, and test recovery as well as failure. A breaker does not replace bulkheads, queue limits, or graceful fallback where those are needed.

Trace enrichment and diagnostics

Outgoing HTTP instrumentation can create activities and propagate trace context to cooperating services. When an application uses .NET distributed tracing and an OpenTelemetry-compatible exporter, these activities can appear as spans in a trace alongside inbound requests and other dependencies. A trace ID helps connect work across services; it does not, by itself, explain why a request failed.

Useful enrichment includes stable, low-cardinality attributes such as a logical dependency name, operation category, or deployment environment. Record retry attempts and breaker state through supported diagnostics or carefully designed instrumentation, so operators can distinguish an original failure from a later attempt. Prefer structured logs and metrics for aggregate counts and rates, and use traces to inspect individual request paths.

Do not attach authorization headers, cookies, access tokens, request bodies, personal data, or other secrets to spans or logs. Avoid attributes whose values vary per user or request when they would create high-cardinality metrics. Check the instrumentation and exporter configuration: redaction, sampling, and captured HTTP fields vary by setup. Trace enrichment should add operational context without changing request semantics or exposing sensitive information.

Choosing and testing a policy

Start from the downstream API’s contract and the application’s latency budget, not from a desire to retry every error. Define which operations can be repeated, which failures qualify, and what the caller should receive when the dependency remains unavailable.

  • For safe, idempotent reads, use a small bounded retry policy for transient failures, with backoff and a total deadline.
  • For writes, confirm idempotency support or another duplicate-prevention mechanism before retrying.
  • Use a circuit breaker to reduce repeated calls during sustained failure, and decide whether the application can return cached, partial, or explicitly unavailable results.
  • Test timeouts, cancellation, transient responses, persistent outages, recovery, and duplicate-write scenarios. Verify both the actual number of requests and the trace or log evidence.

A useful misconception to avoid is that a retry guarantees delivery. It guarantees only another attempt under configured conditions; the client may not know whether a previous attempt reached or changed the server. Resilience is therefore a combination of bounded behavior, API-level semantics, and clear failure handling.

Frequently Asked Questions

Does .NET 10 retry every failed HTTP request automatically?
No. Retries apply only when a resilience handler is registered and the failure matches its configured conditions. Request method, status code, cancellation, and policy settings all matter.

Can I safely retry a POST request?
Not in general. Retry it only when the operation is inherently safe to repeat or the server offers a documented deduplication mechanism, such as an idempotency key used consistently for the same operation.

What is the difference between a retry and a circuit breaker?
A retry repeats an individual request after a qualifying failure. A circuit breaker temporarily stops calls after a pattern of failures, helping avoid continued load on a dependency that appears unhealthy.

Does a circuit breaker replace timeouts?
No. A timeout limits waiting for an individual attempt or overall operation. A breaker reacts to a pattern of outcomes and can reject calls before they are sent.

How do I add trace information to outgoing requests?
Use the application’s HTTP and distributed-tracing instrumentation, then add only safe, useful attributes through supported instrumentation hooks. Confirm that the exporter captures them and that sensitive headers or data are excluded.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.