https://github.com/rluders/gofsm
Simple Finite State Machine written in Go that can play with Redis and Kafka.
https://github.com/rluders/gofsm
finite-state-machine fsm go golang kafka kubernetes microservice redis
Last synced: 29 days ago
JSON representation
Simple Finite State Machine written in Go that can play with Redis and Kafka.
- Host: GitHub
- URL: https://github.com/rluders/gofsm
- Owner: rluders
- License: mit
- Created: 2025-03-24T10:36:15.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-03-25T18:37:47.000Z (about 1 month ago)
- Last Synced: 2025-03-28T01:51:48.685Z (about 1 month ago)
- Topics: finite-state-machine, fsm, go, golang, kafka, kubernetes, microservice, redis
- Language: Go
- Homepage:
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GOFSM
An extensible Finite State Machine (FSM) library for Go, designed for event-driven and distributed systems.
> [!WARNING]
> This library was initially created as a proof of concept (PoC) to solve a specific coordination issue in a distributed system.
> It is **not production-ready** and may contain bugs or limitations that have not yet been addressed.
> Contributions, suggestions, and improvements are **very welcome**!## 🧩 What Problem Does It Solve?
In distributed systems, managing workflows and transitions across multiple services can become complex—especially when coordination, concurrency, and external events are involved.
`gofsm` aims to provide a decoupled, pluggable, and testable FSM core that allows:
- Safe state transitions under concurrency (with Redis locking support)
- Reactive behavior driven by events (from Kafka, HTTP, etc.)
- Clean separation between FSM logic and infrastructure concernsIt is ideal for scenarios such as:
- Orchestrating Kubernetes jobs
- Reacting to Kafka or event-stream inputs
- Coordinating microservices through stateful flows## ✨ Features
- Reusable FSM engine with `OnEnter`, `HandleEvent`, and `OnExit` lifecycle hooks
- Fully decoupled from transport and storage
- Pluggable storage layer with Redis adapter (uses lock + retry)
- Optional Kafka integration using `segmentio/kafka-go`
- Support for `TransitionHook` to notify or trigger side-effects
- Designed for testability and distributed coordination## 📦 Installation
```bash
go get github.com/rluders/gofsm@latest
```## 🚀 Basic Usage
```go
engine, err := fsm.NewFSM([]fsm.State{
&MyInitialState{},
&MyFinalState{},
}, fsm.WithStateStorage(myStorage))// Triggering an event
err = engine.Trigger(ctx, "entity-id", fsm.NewBasicEvent("MyEvent", nil))
```## 📄 License
MIT