# `RpcLoadBalancer.LoadBalancer.SelectionAlgorithm.HashRing`
[🔗](https://github.com/MikaAK/rpc_load_balancer/blob/main/lib/rpc_load_balancer/load_balancer/selection_algorithm/hash_ring.ex#L1)

Consistent hash ring node selection algorithm powered by `libring`.

Routes requests to nodes based on a caller-provided `:key` option.
Each physical node is placed on the ring as virtual nodes (shards)
so that topology changes only redistribute a minimal number of keys.

Supports replica selection via `choose_nodes/4` — returns multiple
distinct nodes for a given key, useful for replication strategies.

When no key is provided, falls back to random selection.

## Usage

    RpcLoadBalancer.LoadBalancer.start_link(
      name: :my_balancer,
      selection_algorithm: RpcLoadBalancer.LoadBalancer.SelectionAlgorithm.HashRing,
      algorithm_opts: [weight: 200]
    )

    RpcLoadBalancer.LoadBalancer.select_node(:my_balancer, key: "user:123")

    {:ok, [primary, replica]} =
      RpcLoadBalancer.LoadBalancer.select_nodes(:my_balancer, 2, key: "user:123")

## Options

- `:weight` — number of virtual nodes (shards) per physical node (default: 128)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
