Expand description
A protocol-agnostic load balancing strategy engine for Rust.
loadwise is a facade crate that re-exports everything from
loadwise_core and optionally integrates with Tower and Redis
via feature flags.
§Quick start
use loadwise::{Strategy, SelectionContext};
use loadwise::strategy::RoundRobin;
let strategy = RoundRobin::new();
let backends = ["10.0.0.1:8080", "10.0.0.2:8080", "10.0.0.3:8080"];
let ctx = SelectionContext::default();
let idx = strategy.select(&backends, &ctx).unwrap();
println!("route to {}", backends[idx]);§Feature flags
| Flag | Enables |
|---|---|
tower | tower module — Tower Layer adapter |
redis | redis module — Redis StateStore backend |
Modules§
- filter
- Filters for narrowing the candidate set before strategy selection.
- health
- Health state machine and tracking for backend nodes.
- metrics
- Optional observability hooks — bring your own Prometheus / OpenTelemetry.
- node
- Traits for describing backend nodes and their observable properties.
- quota
- Per-node multi-dimensional quota tracking.
- state
- Pluggable state storage for per-node runtime data.
- strategy
- Load balancing strategies and the
Strategytrait.
Structs§
- Consecutive
Failure Policy - Marks a node unhealthy after N consecutive failures, recovers after M successes.
- Health
Filter - Filters nodes based on health status. Uses a bitmask internally — zero allocation.
- Health
Tracker - Tracks health state for a set of nodes identified by
Id. - InMemory
Store - In-process
StateStorebacked by aRwLock<HashMap>. - Node
Health - Mutable runtime health counters for a single node.
- Noop
Collector - Default no-op implementation.
- Quota
Config - Per-node quota configuration.
- Quota
Dimension - Configuration for a single quota dimension (e.g., “rpm” or “tpm”).
- Quota
Filter - Filters out nodes whose remaining capacity is below a threshold.
- Quota
Tracker - Tracks rate/quota usage for a set of nodes.
- Selection
Context - Context provided to strategies during node selection.
Enums§
- Health
Status - Current health state of a node.
- Outcome
- Classified result of a request, allowing
HealthPolicyto distinguish between different failure modes.
Traits§
- Filter
- Determines whether a node is eligible for selection.
- Health
Aware - A node that exposes its health status for filtering.
- Health
Policy - Determines how health status transitions based on success/failure signals.
- Load
Metric - Exposes a load score for load-aware strategies. Lower is better.
- Metrics
Collector - Callback interface for observability. The library never pulls in metrics/tracing dependencies — users implement this to bridge to their own stack.
- Node
- A backend node that can be selected by a load balancing strategy.
- Rate
Metric - Exposes remaining capacity for quota-aware strategies. Higher is better.
- State
Store - Generic key-value store for per-node runtime state (latency, quotas, counters, etc.).
- Strategy
- A load balancing strategy that selects a node from a list of candidates.
- Weighted
- Exposes a weight for weighted strategies. Higher weight = more traffic.