AtlasDB is a distributed key-value database built from scratch in Java and Spring Boot, implementing the Raft consensus algorithm for leader election, log replication, fault tolerance, and automatic recovery.
The project demonstrates how modern distributed systems such as etcd, Consul, TiKV, and CockroachDB maintain strong consistency across multiple nodes while tolerating failures.
- Leader Election
- Randomized Election Timeouts
- Heartbeats (AppendEntries RPC)
- Term-based Leadership
- Automatic Leader Failover
- Majority Quorum-Based Decisions
- Write-Ahead Logging (WAL)
- Log Replication Across Nodes
- Commit Index Management
- Majority Acknowledgement Before Commit
- Incremental Follower Synchronization
- Log Consistency Verification
- Automatic Log Repair using nextIndex
- Follower Crash Recovery
- Persistent Raft State
- Persistent Log Storage
- Snapshot-Based Recovery
- Automatic Cluster Healing
- Node Rejoin Synchronization
- In-Memory State Machine
- ConcurrentHashMap-Based KV Store
- Write-Ahead Log Persistence
- Snapshot Creation
- Log Compaction
- Cluster Status Endpoint
- Leader Identification
- Commit Index Tracking
- Election Monitoring
Client
|
REST API
|
+------------+------------+
| |
Leader Followers
Node-1 Node-2
| |
+------ Raft RPC ---------+
| |
Follower
Node-3
-------------------
| Raft Layer |
-------------------
|
-------------------
| Raft Log |
-------------------
|
-------------------
| Commit Index |
-------------------
|
-------------------
| State Machine |
-------------------
|
-------------------
| Snapshot Store |
-------------------
FOLLOWER
|
Election Timeout
|
v
CANDIDATE
|
RequestVote RPC
|
Majority Votes
|
v
LEADER
Client Write
|
v
Leader Append Log
|
Replicate to Followers
|
Majority Acknowledgement
|
Commit Entry
|
Apply To State Machine
Follower Crash
|
Follower Restart
|
Load Snapshot
|
Load Persistent Log
|
Incremental Synchronization
|
Cluster Consistent
src/main/java/com/cfs/backend
├── controller
│ ├── KVController
│ ├── VoteController
│ ├── HeartbeatController
│ ├── ReplicationController
│ └── ClusterController
│
├── raft
│ ├── RaftNode
│ ├── RaftLog
│ ├── RaftLogStore
│ ├── ElectionService
│ ├── VoteService
│ ├── HeartbeatService
│ ├── ReplicationService
│ ├── LogReplicationService
│ ├── CommitService
│ ├── ReplicationTracker
│ ├── PersistentRaftState
│ └── RaftStateManager
│
├── storage
│ ├── StateMachine
│ ├── WALManager
│ ├── StateMachineApplier
│ └── RecoveryManager
│
├── snapshot
│ ├── Snapshot
│ └── SnapshotManager
│
├── dto
│ └── ClusterStatus
│
├── exception
│ ├── NotLeaderException
│ └── GlobalExceptionHandler
│
└── model
├── LogEntry
├── VoteRequest
├── VoteResponse
├── AppendEntriesRequest
├── AppendEntriesResponse
├── ReplicationRequest
├── ReplicationResponse
├── CommitRequest
├── CommitResponse
├── SyncRequest
└── SyncResponse
mvn spring-boot:run \
-Dspring-boot.run.profiles=node1mvn spring-boot:run \
-Dspring-boot.run.profiles=node2mvn spring-boot:run \
-Dspring-boot.run.profiles=node3POST /kv
{
"key":"user",
"value":"aman"
}GET /kv/userDELETE /kv/userGET /cluster/statusExample Response:
{
"nodeId":"node-1",
"role":"LEADER",
"currentTerm":12,
"leaderId":"node-1",
"commitIndex":157
}Start all three nodes.
Node1 -> Leader
Node2 -> Follower
Node3 -> Follower
Insert records.
PUT user=aman
PUT city=delhi
Terminate leader.
Node1 Down
Automatic election occurs.
Node2 -> Leader
Node3 -> Follower
Continue writes successfully.
PUT country=india
Restart Node1.
Node1 -> Follower
Node1 -> Synchronizes Logs
Node1 -> Cluster Consistent
- Raft Consensus Algorithm
- Distributed Systems Fundamentals
- Strong Consistency
- Quorum-Based Commit
- Leader Election
- Heartbeats
- Log Replication
- Commit Index
- Write-Ahead Logging
- Crash Recovery
- Persistent Metadata
- Snapshotting
- Log Compaction
- Incremental Synchronization
- Conflict Resolution
- Automatic Log Repair
- Fault Tolerance
- InstallSnapshot RPC
- Linearizable Reads
- Membership Changes
- Dynamic Cluster Scaling
- Prometheus Metrics
- Grafana Dashboards
- Docker Deployment
- Kubernetes Deployment
- gRPC-Based Replication
- Multi-Raft Sharding
- SQL Layer
- Distributed Transactions
This project draws inspiration from the design principles used in:
- etcd
- Consul
- TiKV
- CockroachDB
- Apache Ratis
while implementing the core algorithms from scratch for educational and engineering purposes.