Skip to main content

Crate loadwise

Crate loadwise 

Source
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

FlagEnables
towertower module — Tower Layer adapter
redisredis 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 Strategy trait.

Structs§

ConsecutiveFailurePolicy
Marks a node unhealthy after N consecutive failures, recovers after M successes.
HealthFilter
Filters nodes based on health status. Uses a bitmask internally — zero allocation.
HealthTracker
Tracks health state for a set of nodes identified by Id.
InMemoryStore
In-process StateStore backed by a RwLock<HashMap>.
NodeHealth
Mutable runtime health counters for a single node.
NoopCollector
Default no-op implementation.
QuotaConfig
Per-node quota configuration.
QuotaDimension
Configuration for a single quota dimension (e.g., “rpm” or “tpm”).
QuotaFilter
Filters out nodes whose remaining capacity is below a threshold.
QuotaTracker
Tracks rate/quota usage for a set of nodes.
SelectionContext
Context provided to strategies during node selection.

Enums§

HealthStatus
Current health state of a node.
Outcome
Classified result of a request, allowing HealthPolicy to distinguish between different failure modes.

Traits§

Filter
Determines whether a node is eligible for selection.
HealthAware
A node that exposes its health status for filtering.
HealthPolicy
Determines how health status transitions based on success/failure signals.
LoadMetric
Exposes a load score for load-aware strategies. Lower is better.
MetricsCollector
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.
RateMetric
Exposes remaining capacity for quota-aware strategies. Higher is better.
StateStore
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.