Add distributed supervisor using Horde-like patterns for fault-tolerant customer actor management with graceful shutdown #4
+1,892
−43
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a distributed supervisor system inspired by Horde patterns to provide fault-tolerant, scalable customer actor management across cluster nodes with support for graceful node shutdown and zero-downtime actor migration.
Overview
The implementation adds distributed computing capabilities to the existing Gleam customer API, enabling automatic load balancing, fault tolerance, cluster membership management, and graceful node shutdown similar to Elixir's Horde library.
Key Features Added
Distributed Supervisor with Horde-like Functionality
OTP Actor System
gleam_otp
Configuration Management
Architecture
The system uses consistent hashing to determine which node should host each customer actor:
When topology changes occur (nodes joining/leaving) or during graceful shutdown, the system automatically rebalances and migrates actors to maintain optimal distribution.
Graceful Shutdown Process
Usage Examples
The system supports dual operation modes for backward compatibility:
Files Added/Modified
Core Implementation
src/distributed_supervisor.gleam
- Main distributed supervisor with consistent hashing and graceful shutdownsrc/app_supervisor.gleam
- Application supervisor for OTP compliancesrc/config.gleam
- Configuration management for distributed operationsrc/distributed_customer_api.gleam
- Distributed mode demonstration with graceful shutdown demoEnhanced Existing Files
src/customer_api.gleam
- Updated to support both legacy and distributed modessrc/customer_actor.gleam
- Enhanced with proper OTP actorsgleam.toml
- Addedgleam_otp
andgleam_erlang
dependenciesTesting & Documentation
test/distributed_supervisor_test.gleam
- Unit tests for distributed components including graceful shutdown testsREADME.md
andARCHITECTURE.md
with distributed system documentation and graceful shutdown detailsdistributed_demo.sh
- Interactive demonstration scriptBenefits
This implementation provides:
The distributed supervisor successfully bridges the gap between Elixir's Horde and Gleam's functional programming paradigm, providing a robust foundation for building scalable, fault-tolerant distributed systems on the BEAM VM with zero-downtime operational capabilities.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.