Seamless Distribution
View SourceIn today’s world of scalable, resilient applications, distributed systems are no longer optional—they’re essential. Enter DistributedSupervisor, a specialized Elixir library designed to transform how you manage processes across distributed environments.
Transparent Process Distribution in Elixir Made Simple
Building distributed applications in Elixir has traditionally involved complex coordination, manual process distribution, and custom recovery mechanisms. DistributedSupervisor changes this paradigm by extending Elixir’s built-in DynamicSupervisor with powerful distributed capabilities that work transparently across your entire cluster.
# Start with minimal configuration
{:ok, pid} = DistributedSupervisor.start_link(name: MyApp.DistSup)
# Process automatically distributed across the cluster
{:ok, child_pid, child_name} = DistributedSupervisor.start_child(MyApp.DistSup, MyWorker)Core Distributed Features That Set It Apart
Intelligent Process Distribution
At the heart of DistributedSupervisor is a consistent hashing mechanism powered by HashRing that ensures:
- Balanced Load: Processes are evenly distributed across all connected nodes
- Predictable Allocation: The same key consistently maps to the same node
- Minimal Reshuffling: When nodes join or leave, only a fraction of processes need to move
Dynamic Cluster Adaptation
Your application automatically adapts to changing cluster conditions:
- Node Join Events: When new nodes come online, the process distribution automatically expands
- Node Leave Events: When nodes disconnect, their processes are automatically redistributed
- Configurable Monitoring: Choose how your application responds to cluster topology changes
Fine-Grained Control
While automation is the default, you maintain complete control when needed:
# Explicitly assign a process to a specific node
{:ok, pid, name} = DistributedSupervisor.start_child(
MyApp.DistSup,
MyWorker,
:"node1@host"
)
# Check distribution information
target_node = DistributedSupervisor.node_for(MyApp.DistSup, :some_key)
is_local = DistributedSupervisor.mine?(MyApp.DistSup, :some_key)Built-in Fault Tolerance
When nodes fail, DistributedSupervisor ensures your application keeps running:
- Automatic Recovery: Child processes are restarted on remaining nodes
- Cached Child Specifications: Process definitions are preserved for recovery
- Configurable Restart Strategies: Choose between permanent, transient, or temporary behaviors
Technical Benefits for Modern Applications
Familiar, Ergonomic API
DistributedSupervisor’s API mirrors Elixir’s standard DynamicSupervisor, making adoption seamless:
# Interact with distributed processes using familiar patterns
result = DistributedSupervisor.call(MyApp.DistSup, worker_name, :get_status)
DistributedSupervisor.cast(MyApp.DistSup, worker_name, {:update, value})
# Get information about processes across the cluster
children = DistributedSupervisor.children(MyApp.DistSup)Comprehensive Event Notifications
Create listeners to respond to process lifecycle events:
defmodule MyApp.ProcessListener do
@behaviour DistributedSupervisor.Listener
def handle_node_up(node, state) do
# React when a node joins the cluster
{:ok, state}
end
def handle_node_down(node, state) do
# React when a node leaves the cluster
{:ok, state}
end
endBuilt on Solid Foundations
Leveraging proven Erlang/Elixir components:
:pgfor distributed process groupsHashRingfor consistent hash-based distributionDynamicSupervisorfor robust process supervision
Real-World Applications
High-Availability Systems
Ensure your critical services continue operating even when nodes fail:
- Distributed caching layers that survive node failures
- Always-available API endpoints with automatic failover
- Resilient job processing queues that redistribute work
Horizontal Scaling
Scale your application by simply adding new nodes—processes automatically distribute:
- Stateful microservices that scale with demand
- Distributed task processing systems
- Load-balanced service clusters
Stateful Service Management
Manage stateful components across your cluster:
- Session stores with consistent routing
- Distributed locks and coordinators
- State machine replicas with predictable distribution
Getting Started is Simple
Add DistributedSupervisor to your project:
def deps do
[
{:distributed_supervisor, "~> 0.5"}
]
endWhy Choose DistributedSupervisor?
- Simplicity: Distributed features with minimal configuration
- Reliability: Built-in fault tolerance and recovery mechanisms
- Flexibility: Fine-grained control when you need it
- Familiar: API that builds on existing Elixir patterns
- Lightweight: Minimal overhead for distributed coordination
Transform your Elixir applications into resilient, distributed systems today with DistributedSupervisor—where distribution becomes transparent and reliability comes standard.