Expand description
§do-over
An async-first resilience and transient fault handling library for Rust, inspired by the .NET Polly library.
§Overview
do-over provides a set of resilience policies that can be used to make your
applications more robust when dealing with transient failures, network issues,
and other common problems in distributed systems.
§Policies
retry::RetryPolicy- Retry failed operations with configurable backoffcircuit_breaker::CircuitBreaker- Prevent cascading failurestimeout::TimeoutPolicy- Time-bound operationsbulkhead::Bulkhead- Limit concurrent executionsrate_limit::RateLimiter- Token bucket rate limitinghedge::Hedge- Hedged requests for latency reductionfallback::FallbackExt- Return default values on failurecache::TypedCache- Cache successful resultswrap::Wrap- Compose multiple policies together
§Utilities
context::Context- Pass metadata through policy execution
§Quick Start
use do_over::{policy::Policy, retry::RetryPolicy, timeout::TimeoutPolicy, wrap::Wrap, error::DoOverError};
use std::time::Duration;
// Create a policy that retries 3 times with a 5s timeout per attempt
let policy = Wrap::new(
RetryPolicy::fixed(3, Duration::from_millis(100)),
TimeoutPolicy::new(Duration::from_secs(5)),
);
// Execute your operation with resilience
let result: Result<&str, DoOverError<&str>> = policy.execute(|| async {
Ok("success")
}).await;§Policy Composition
Policies can be composed using wrap::Wrap. The recommended ordering
(from outer to inner) is:
- Bulkhead - Limit concurrency first
- Circuit Breaker - Fast-fail if too many errors
- Rate Limiter - Throttle requests
- Retry - Handle transient failures
- Timeout - Bound individual attempts
§Feature Flags
http- Enables reqwest integrationmetrics-prometheus- Prometheus metricsmetrics-otel- OpenTelemetry metrics
Modules§
- bulkhead
- Bulkhead policy for concurrency limiting.
- cache
- Cache policy for caching successful results.
- circuit_
breaker - Circuit breaker policy for preventing cascading failures.
- context
- Policy context for passing metadata through execution.
- error
- Error types for do_over policies.
- fallback
- Fallback policy for providing default values on failure.
- hedge
- Hedge policy for reducing tail latency.
- metrics
- policy
- Core policy trait for resilience patterns.
- rate_
limit - Rate limiter policy using a token bucket algorithm.
- retry
- Retry policy for handling transient failures.
- timeout
- Timeout policy for time-bounded operations.
- tower
- wrap
- Policy composition using the Wrap combinator.