https://github.com/cedi/zig-raft
Just a learning repo, implementing raft (maybe) in zig
https://github.com/cedi/zig-raft
Last synced: 19 days ago
JSON representation
Just a learning repo, implementing raft (maybe) in zig
- Host: GitHub
- URL: https://github.com/cedi/zig-raft
- Owner: cedi
- Created: 2026-05-22T18:08:47.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2026-05-26T12:55:57.000Z (about 1 month ago)
- Last Synced: 2026-05-26T14:16:57.029Z (about 1 month ago)
- Language: Zig
- Size: 19.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# zig raft
Hopefully, one day a full [raft] implementation in [zig].
Why? Because.
> [!NOTE]
> This is just a research project for me to learn [zig] and have fun implementing [raft]
[zig]: https://ziglang.org/
[raft]: https://raft.github.io/
## Design
```mermaid
flowchart TD
client[Client]
server[Server]
log[Log]
sm[StateMachine]
client --> server
server -->|apppend| log
log -->|apply| sm
sm -->|result via future| server
```
### Log Structure
See [wal-format](./docs/wal-format.md)
### State Machine
```mermaid
flowchart TD
A[apply_loop ticks] --> B{applied_index < commit_index?}
B -->|no| A
B -->|yes| C[cmd = log.get
applied_index + 1]
C --> D{cmd_tag}
D -->|Set| E[map.put key, value]
D -->|Delete| F[map.remove key]
D -->|Cas| G{map.get key == expected?}
G -->|yes| H[map.put key, new]
G -->|no| I[result: CasMismatch]
E --> J[applied_index += 1]
F --> J
H --> J
I --> J
J --> K[wake waiter for this index]
K --> A
```