Expand description
§reliability-toolkit
Async reliability primitives for Tokio-based Rust services. The crate is deliberately small: each primitive is independent, composable, and avoids pulling in unrelated dependencies.
§Primitives
RateLimiter— token-bucket rate limiter with configurable burst.CircuitBreaker— closed → open → half-open with failure-rate trip and cool-down.Retry— exponential backoff with full jitter and per-error predicates.Bulkhead— semaphore-backed concurrency cap.
§Composition
Each primitive exposes an execute() (or run() / acquire()) that wraps
a user-supplied future. They are designed so the typical layering pattern —
Retry(CircuitBreaker(Bulkhead(RateLimit(call)))) — falls out naturally.
use std::time::Duration;
use reliability_toolkit::{RateLimiter, CircuitBreaker, Retry, Bulkhead, RetryConfig};
let limiter = RateLimiter::new(100.0, 100); // 100 rps, burst 100
let breaker = CircuitBreaker::builder()
.failure_threshold(5)
.cool_down(Duration::from_secs(10))
.build();
let retry = Retry::new(RetryConfig::default());
let pool = Bulkhead::new(20);
let result: Result<(), std::io::Error> = retry
.run(|| async {
limiter.acquire().await;
let _permit = pool
.acquire()
.await
.map_err(std::io::Error::other)?;
match breaker.call(async { Ok::<_, std::io::Error>(()) }).await {
Ok(inner) => inner,
Err(open) => Err(std::io::Error::other(open.to_string())),
}
})
.await;Re-exports§
pub use bulkhead::Bulkhead;pub use bulkhead::BulkheadPermit;pub use circuit_breaker::CircuitBreaker;pub use circuit_breaker::CircuitBreakerBuilder;pub use circuit_breaker::CircuitState;pub use error::ToolkitError;pub use rate_limiter::RateLimiter;pub use retry::Retry;pub use retry::RetryConfig;pub use audit_stream::AuditingBreaker;
Modules§
- audit_
stream - Optional audit-stream-py producer. Gated behind the
audit-streamCargo feature so the core toolkit stays HTTP-free. Optional audit-stream-py producer. - bulkhead
- Bulkhead — semaphore-backed concurrency cap.
- circuit_
breaker - Circuit breaker.
- error
- Error types shared across the crate.
- rate_
limiter - Token-bucket rate limiter.
- retry
- Exponential backoff with full jitter.