An Elixir library for executing Remote Procedure Calls across distributed BEAM nodes with a built-in load balancer. It wraps Erlang's :erpc module with structured error handling and provides a pluggable node selection layer powered by OTP's :pg process groups.
Features
- RPC wrappers —
call/5andcast/4around:erpcwithErrorMessageerror tuples - Distributed load balancer — automatic node discovery and registration via
:pg - Six selection algorithms — Random, Round Robin, Least Connections, Power of Two, Hash Ring, Weighted Round Robin
- Custom algorithms — implement the
SelectionAlgorithmbehaviour to add your own - Node filtering — restrict which nodes join a balancer with string or regex patterns
- Connection tracking — ETS-backed atomic counters for connection-aware algorithms
Installation
Add rpc_load_balancer to your list of dependencies in mix.exs:
def deps do
[
{:rpc_load_balancer, "~> 0.1.0"}
]
endQuick Start
{:ok, result} =
RpcLoadBalancer.call(
:"worker@host",
MyModule,
:some_fun,
["arg"],
timeout: :timer.seconds(5)
)
{:ok, _pid} = RpcLoadBalancer.LoadBalancer.start_link(name: :my_balancer)
{:ok, result} = RpcLoadBalancer.LoadBalancer.call(:my_balancer, MyModule, :my_fun, [arg])Documentation
This project's documentation follows the Diátaxis framework:
Tutorials
- Getting Started — learn the library by building a load-balanced RPC setup step by step
How-To Guides
- Write a Custom Selection Algorithm
- Use Hash-Based Routing
- Filter Which Nodes Join a Balancer
- Use Connection-Tracking Algorithms
- Configure Weighted Round Robin
Reference
- Full API Reference — types, functions, callbacks, and internal modules
Explanation
- Architecture and Design Decisions — how the components fit together and why