https://github.com/ksrichard/easyraft
Easy to use Raft library to make your app distributed, highly available and fault-tolerant
https://github.com/ksrichard/easyraft
cluster discovery fault-tolerant high-availability raft
Last synced: 10 months ago
JSON representation
Easy to use Raft library to make your app distributed, highly available and fault-tolerant
- Host: GitHub
- URL: https://github.com/ksrichard/easyraft
- Owner: ksrichard
- License: apache-2.0
- Created: 2021-12-01T06:59:06.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-03T07:13:18.000Z (over 4 years ago)
- Last Synced: 2024-06-19T04:13:45.528Z (about 2 years ago)
- Topics: cluster, discovery, fault-tolerant, high-availability, raft
- Language: Go
- Homepage:
- Size: 170 KB
- Stars: 68
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://goreportcard.com/report/github.com/ksrichard/easyraft)
[](https://pkg.go.dev/github.com/ksrichard/easyraft)
[](https://github.com/ksrichard/easyraft)
[](https://github.com/ksrichard/easyraft/releases/latest/)
An easy to use customizable library to make your Go application Distributed, Highly available, Fault Tolerant etc...
using Hashicorp's [Raft](https://github.com/hashicorp/raft) library which implements the
[Raft Consensus Algorithm](https://raft.github.io/).
Features
---
- **Configure and start** a fully functional Raft node by writing ~10 lines of code
- **Automatic Node discovery** (nodes are discovering each other using Discovery method)
1. **Built-in discovery methods**:
1. **Static Discovery** (having a fixed list of nodes addresses)
2. **mDNS Discovery** for local network node discovery
3. **Kubernetes discovery**
- **Cloud Native** because of kubernetes discovery and easy to load balance features
- **Automatic forward to leader** - you can contact any node to perform operations, everything will be forwarded to the
actual leader node
- **Node monitoring/removal** - the nodes are monitoring each other and if there are some failures then the offline
nodes get removed automatically from cluster
- **Simplified state machine** - there is an already implemented generic state machine which handles the basic
operations and routes requests to State Machine Services (see **Examples**)
- **All layers are customizable** - you can select or implement your own **State Machine Service, Message Serializer**
and **Discovery Method**
- **gRPC transport layer** - the internal communications are done through gRPC based communication, if needed you can
add your own services
**Note:** snapshots are not supported at the moment, will be handled at later point
**Note:** at the moment the communication between nodes are insecure, I recommend to not expose that port
Get Started
---
You can create a simple EasyRaft Node with local mDNS discovery, an in-memory Map service and MsgPack as serializer(this
is the only one built-in at the moment)
```go
import (
"github.com/ksrichard/easyraft"
"github.com/ksrichard/easyraft/discovery"
"github.com/ksrichard/easyraft/fsm"
"github.com/ksrichard/easyraft/serializer"
)
func main() {
raftPort := 5000
discoveryPort := 5001
dataDir := "s1"
node, err := easyraft.NewNode(
raftPort,
discoveryPort,
dataDir,
[]fsm.FSMService{fsm.NewInMemoryMapService()},
serializer.NewMsgPackSerializer(),
discovery.NewMDNSDiscovery(),
false,
)
if err != nil {
panic(err)
}
stoppedCh, err := node.Start()
if err != nil {
panic(err)
}
defer node.Stop()
}
```
Examples
---
Examples can be found in the [examples](https://github.com/ksrichard/easyraft/tree/main/examples/) directory
Build
---
To regenerate gRPC code and install dependencies simply run `make install`
TODO
---
- [ ] Add more examples
- [ ] Test coverage
- [ ] Secure communication between nodes (SSL/TLS)
- [ ] Backup/Restore backup handling
- [ ] Allow configuration option to pass any custom raft.FSM