{"id":21301300,"url":"https://github.com/sajalkmr/raftly","last_synced_at":"2025-07-09T09:06:18.677Z","repository":{"id":260955423,"uuid":"882800680","full_name":"sajalkmr/raftly","owner":"sajalkmr","description":"Basic Implementation of Raft Consensus Algorithm in Java","archived":false,"fork":false,"pushed_at":"2024-12-12T10:58:07.000Z","size":50,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T08:12:39.081Z","etag":null,"topics":["distributed-systems","java","raft-consensus-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sajalkmr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-03T19:43:34.000Z","updated_at":"2025-01-12T08:04:50.000Z","dependencies_parsed_at":"2024-11-03T21:26:24.447Z","dependency_job_id":"5d7ff58e-ed98-43ef-b0f4-09d2c6277ffe","html_url":"https://github.com/sajalkmr/raftly","commit_stats":null,"previous_names":["sajalkmr/raftly"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajalkmr%2Fraftly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajalkmr%2Fraftly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajalkmr%2Fraftly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajalkmr%2Fraftly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sajalkmr","download_url":"https://codeload.github.com/sajalkmr/raftly/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243772056,"owners_count":20345570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-systems","java","raft-consensus-algorithm"],"created_at":"2024-11-21T15:44:58.989Z","updated_at":"2025-03-15T18:25:01.093Z","avatar_url":"https://github.com/sajalkmr.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raftly\n\nA Java implementation of the Raft consensus algorithm, providing a robust distributed consensus solution.\n\n## Overview\n\nRaftly is a complete implementation of the Raft consensus protocol, featuring:\n- Leader election with randomized timeouts\n- Log replication with consistency guarantees\n- State machine replication\n- Membership management\n- Thread-safe operations\n- Configurable timeouts and heartbeat intervals\n- Proper error handling and recovery mechanisms\n\n## Getting Started\n\n### Prerequisites\n- Java 8 or higher\n- Maven 3.6 or higher\n- Git\n\n### Setup\n1. Clone the repository:\n```bash\ngit clone https://github.com/sajalkmr/raftly.git\ncd raftly\n```\n\n2. Build the project:\n```bash\nmvn clean install\n```\n\n### Running the Demo\n1. Start a local cluster with 3 nodes:\n```bash\nmvn exec:java -Dexec.mainClass=\"com.raftly.RaftDemo\"\n```\n\n2. The demo will:\n- Initialize a 3-node Raft cluster\n- Demonstrate leader election\n- Show log replication in action\n- Display state machine consistency\n\n## Configuration\n\n### Default Settings\n```properties\n# Core Raft settings\nraft.election.timeout.base=1500\nraft.election.timeout.range=750\nraft.heartbeat.interval=1000\nraft.commit.check.interval=500\n\n# Cluster settings\nraft.cluster.size=3\n```\n\n### Customizing Configuration\nYou can modify these settings by:\n1. Updating the constants in `RaftNode.java`\n2. Passing custom values during node initialization\n\n## Architecture\n\n### Core Components\n\n#### RaftNode\n- Implements the core Raft consensus logic\n- Manages node state (Follower/Candidate/Leader)\n- Handles leader election and log replication\n- Uses scheduled tasks for timeouts and heartbeats\n\n#### Log\n- Thread-safe log entry management\n- Handles log consistency and conflict resolution\n- Supports atomic append operations\n- Maintains log indices and terms\n\n#### StateMachine\n- Applies committed log entries\n- Maintains consistent state across the cluster\n- Supports state snapshots and recovery\n\n### Thread Safety\n- Uses `ReentrantLock` for state modifications\n- Atomic operations for critical state changes\n- Read-write locks for log access\n- Thread-safe scheduled operations\n\n## Usage Examples\n\n### Basic Cluster Setup\n```java\n// Initialize components\nStateMachine stateMachine = new StateMachine();\nLog log = new Log();\nRaftNode node = new RaftNode(0, null, stateMachine, log);\n\n// Create and set up cluster\nList\u003cRaftNode\u003e nodes = Arrays.asList(node);\nRaftCluster cluster = new RaftCluster(nodes);\nnode.setCluster(cluster);\n\n// Start the node\nnode.start();\n```\n\n### Command Replication\n```java\n// Append a command through the leader\nif (node.isLeader()) {\n    LogEntry entry = new LogEntry(currentTerm, \"SET key value\");\n    CompletableFuture\u003cBoolean\u003e future = node.appendCommand(entry);\n    boolean success = future.get(); // Wait for replication\n}\n```\n\n## Error Handling\n\nThe implementation includes robust error handling for:\n- Network partitions\n- Node failures\n- Split votes\n- Log inconsistencies\n- Concurrent operations\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Commit your changes\n4. Push to the branch\n5. Create a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Acknowledgments\n\n- Based on the [Raft Consensus Algorithm paper](https://raft.github.io/raft.pdf) by Diego Ongaro and John Ousterhout\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsajalkmr%2Fraftly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsajalkmr%2Fraftly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsajalkmr%2Fraftly/lists"}