You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A fully distributed file storage system built for the Distributed Systems course at SVNIT Surat.
Implements leader election, round-robin load balancing, data replication, shared metadata, and automatic failover.
# Check current leader
curl http://localhost:8080/master/health
# β {"isLeader":true, "status":"UP"}# Kill primary
docker kill master-1
# Wait 6 seconds β backup promotes itself
curl http://localhost:8090/master/health
# β {"isLeader":true, "status":"UP"} β backup is now leader!# Bring primary back β it becomes backup
docker start master-1
curl http://localhost:8080/master/health
# β {"isLeader":false, "status":"UP"} β back as backup
2. Storage Node Fault Tolerance
# Upload a fileecho"test data"> test.txt
curl -X POST http://localhost/master/upload -F file=@test.txt
# Kill one storage node
docker stop storage-node-1
# Download still works β falls back to storage-node-2
curl -O http://localhost/master/download/test.txt
cat test.txt # β test data
3. Round Robin Load Balancing
# Upload multiple files and watch docker logs# Requests alternate between server-node-1 and server-node-2
docker logs master-1 2>&1| grep "Round robin selected"
Distributed Computing Concepts
Concept
Implementation
Consistent Hashing
Storage node selection β minimizes remapping when nodes change
Data Replication
Every file stored on all storage nodes (replication factor = 2)
Leader Election
Simplified Raft β primary/backup masters, promotes in 5s
Fault Tolerance
Download falls back to replica if storage node is down
Load Balancing
Round-robin across server nodes using AtomicInteger
Shared State
MySQL as distributed metadata store β all nodes in sync
Health Monitoring
Periodic pings every 5-10s, automatic alive-list maintenance
Reverse Proxy
Nginx β single entry point, transparent master failover
CAP Theorem
AP system β Available + Partition Tolerant
Eventual Consistency
MySQL metadata may briefly lag under high load
Database Schema
-- File metadata (one row per uploaded file)CREATETABLEfile_metadata (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
file_name VARCHAR(255) NOT NULL,
file_size BIGINTNOT NULL,
content_type VARCHAR(100),
checksum VARCHAR(64),
storage_nodes VARCHAR(500), -- "http://storage-node-1:8091,http://storage-node-2:8092"
uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status VARCHAR(20) DEFAULT 'ACTIVE'
);
-- Server node registryCREATETABLEserver_nodes (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
node_url VARCHAR(255) NOT NULL UNIQUE,
status VARCHAR(20) DEFAULT 'UP',
last_heartbeat TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
registered_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Phase Comparison
Feature
Phase 1
Phase 2
Master nodes
1 (SPOF)
2 (leader election)
Metadata storage
In-memory HashMap
Shared MySQL
Middle layer
None
Server nodes x2
Entry point
Direct :8080
Nginx :80
Master failover
Manual
Automatic (5s)
Containers
3
9
File persistence across restart
Multi-node consistency
Known Limitations
MySQL SPOF β MySQL itself has no replication. Production fix: MySQL Galera Cluster or etcd
Split-brain window β 5-second window where both masters may think they are leader. Production fix: full Raft consensus
No partial write recovery β if server node crashes mid-upload, file may be partially stored
Synchronous replication β upload waits for all storage nodes. Slower but consistent
Course: Distributed Systems β B.Tech CSE, SVNIT Surat
Academic Year: 2025-26
About
A distributed file storage system using Java, Spring Boot & Docker, featuring consistent hashing, file replication across nodes, fault tolerance, and a live health dashboard. Inspired by Amazon S3, HDFS, and Dropbox.