A Fault-Tolerant Distributed Storage System with Intelligent Erasure Coding
COSMEON is a distributed storage system that splits files into encoded shards and distributes them across multiple storage nodes. Even if some nodes fail, the original file can be completely reconstructed from the remaining shards. This system implements erasure coding with intelligent algorithm selection to balance storage efficiency, performance, and cost.
- π§© Intelligent Erasure Coding: Automatically selects between Reed-Solomon, XOR-Parity, or Replication based on file characteristics
- π‘οΈ Fault Tolerance: Files can survive node failures (configurable from 1 to n nodes)
- π Smart Analytics: Analyzes files to choose optimal storage strategy
- π Distributed Storage: Uses Supabase Storage as distributed nodes
- π FastAPI Backend: RESTful API for all operations
- π₯οΈ Rich CLI: Beautiful terminal interface with progress bars and color-coded status
- π Cost Optimization: Estimates storage costs and suggests optimizations
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β CLI Client ββββββΆβ FastAPI Engine ββββββΆβ Storage Grid β
β (Typer/Rich) βββββββ (Python) βββββββ (5 Supabase β
β β β β β Buckets) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β β β
βΌ βΌ βΌ
User Commands Algorithm Selection Shard Distribution
β’ upload β’ File Analysis β’ node-1
β’ reconstruct β’ Reed-Solomon β’ node-2
β’ status β’ XOR-Parity β’ node-3
β’ simulate-failure β’ Replication β’ node-4
β’ node-5
The system uses 5 Supabase Storage buckets to simulate a distributed storage grid:
| Node | Bucket Name | Role | Purpose |
|---|---|---|---|
| π’ Node 1 | node-1 |
Primary | Stores data shards |
| π’ Node 2 | node-2 |
Primary | Stores data shards |
| π’ Node 3 | node-3 |
Primary | Stores data shards |
| π‘ Node 4 | node-4 |
Parity | Stores parity/backup shards |
| π‘ Node 5 | node-5 |
Parity | Stores parity/backup shards |
Default Encoding: Reed-Solomon (3,2) scheme:
- 3 data shards (minimum needed for reconstruction)
- 2 parity shards (can lose any 2 nodes)
- Storage overhead: 167% (5/3 = 1.67x original size)
- Python 3.9+
- Supabase account (free tier)
- Git
git clone https://github.com/yourusername/cosmeon.git
cd cosmeon- Create a new project at supabase.com
- Create 5 storage buckets:
node-1,node-2,node-3,node-4,node-5 - Make all buckets public (for demo purposes)
- Copy your project credentials
# Copy the example env file
cp .env.example .env
# Edit .env with your Supabase credentials
nano .envYour .env should contain:
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
# Storage configuration
STORAGE_BUCKETS=node-1,node-2,node-3,node-4,node-5
DEFAULT_ALGORITHM=reed-solomonpip install -r requirements.txtpython setup_supabase.pyuvicorn main:app --reloadThe API will be available at http://localhost:8000
# Upload a file
cosmeon upload sample.jpg
# Upload with specific algorithm
cosmeon upload backup.zip --algorithm=reed-solomon
# Check file status
cosmeon status <file_id>
# Reconstruct a file
cosmeon reconstruct <file_id> --output=recovered.jpg
# Simulate node failure (demo)
cosmeon simulate-failure node-2| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Health check and system info |
GET |
/nodes/status |
Check status of all storage nodes |
POST |
/upload |
Upload a file with smart encoding |
GET |
/file/{file_id}/status |
Check reconstruction status of a file |
GET |
/file/{file_id}/reconstruct |
Reconstruct file from shards |
GET |
/analytics |
System analytics and cost breakdown |
curl -X POST \
-F "file=@document.pdf" \
-F "algorithm=reed-solomon" \
http://localhost:8000/uploadResponse:
{
"file_id": "550e8400-e29b-41d4-a716-446655440000",
"algorithm": "reed-solomon",
"shards": [
{"bucket": "node-1", "url": "...", "size": 10240},
{"bucket": "node-2", "url": "...", "size": 10240},
{"bucket": "node-3", "url": "...", "size": 10240},
{"bucket": "node-4", "url": "...", "size": 10240},
{"bucket": "node-5", "url": "...", "size": 10240}
],
"storage_cost": 0.00045,
"can_survive_failures": 2
}COSMEON analyzes each file to choose the optimal storage strategy:
| Algorithm | Use Case | Overhead | Fault Tolerance | Best For |
|---|---|---|---|---|
| Replication | Hot data, small files | 300% (3x) | 2/5 nodes | Logs, databases, temp files |
| Reed-Solomon | Cold data, large files | 167% (1.67x) | ANY 2 nodes | Backups, archives, videos |
| XOR-Parity | Balanced needs | 200% (2x) | SOME 2 nodes | Images, documents, mixed use |
- File size: Small β Replication, Large β Reed-Solomon
- File type: Media β XOR-Parity, Archives β Reed-Solomon
- Access pattern: Hot β Replication, Cold β Reed-Solomon
- Criticality: High β Replication, Low β Reed-Solomon
# Reed-Solomon with custom parameters (k=4, m=3)
cosmeon upload data.bin --algorithm=reed-solomon --k=4 --m=3
# Replication with 5 copies
cosmeon upload critical.log --algorithm=replication --factor=5
# XOR-Parity with 4 data + 3 parity shards
cosmeon upload dataset.csv --algorithm=xor-parity --data=4 --parity=3# Use cost-optimization policy
cosmeon upload archive.tar.gz --policy=cost
# Use performance-optimization policy
cosmeon upload video.mp4 --policy=performance
# Use balanced policy (default)
cosmeon upload document.pdf --policy=balanced# Get storage analytics
cosmeon analytics
# Check individual file efficiency
cosmeon analyze <file_id>- Upload a file:
cosmeon upload important_document.pdf- Check where shards are stored:
cosmeon status <file_id>Output shows shards distributed across 5 nodes.
- Simulate node failures:
# Simulate node-2 going offline
cosmeon simulate-failure node-2
# Simulate another failure
cosmeon simulate-failure node-5- Reconstruct the file:
# Even with 2 nodes down, we can reconstruct!
cosmeon reconstruct <file_id> --output=recovered.pdfThe system successfully reconstructs the file using the remaining 3 shards!
| Operation | Replication | Reed-Solomon | XOR-Parity |
|---|---|---|---|
| Upload Speed | β‘β‘β‘β‘β‘ | β‘β‘β‘ | β‘β‘β‘β‘ |
| Download Speed | β‘β‘β‘β‘β‘ | β‘β‘ | β‘β‘β‘β‘ |
| Reconstruction | β‘β‘β‘β‘β‘ | β‘ | β‘β‘β‘ |
| Storage Efficiency | β‘ | β‘β‘β‘β‘β‘ | β‘β‘β‘ |
| Fault Tolerance | β‘β‘β‘β‘ | β‘β‘β‘β‘β‘ | β‘β‘β‘β‘ |
cosmeon/
βββ main.py # FastAPI server
βββ cli.py # Command-line interface
βββ storage_manager.py # Supabase storage operations
βββ smart_engine.py # Intelligent algorithm selection
βββ algorithms.py # Encoding/decoding implementations
βββ setup_supabase.py # Initialization script
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ config.yaml # System configuration
βββ README.md # This file
Note: This is a demonstration system. For production use:
- Don't use public buckets - Implement signed URLs
- Add authentication - Use Supabase Auth or JWT
- Encrypt sensitive data - Encrypt before encoding
- Implement rate limiting - Prevent abuse
- Use private endpoints - Don't expose admin functions
- File Size: Supabase free tier limits files to 50MB
- Total Storage: 5GB limit on free tier
- Public Access: Buckets are public for demo purposes
- Node Count: Fixed at 5 nodes in this implementation
For production with more nodes, see our Scaling Guide which covers:
- Dynamic node allocation (10-100+ nodes)
- Multiple storage providers
- Geographic distribution
- Cost-tiered storage
- Automatic rebalancing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Reed-Solomon implementation:
reedsololibrary - Storage: Supabase
- CLI: Typer + Rich
- API Framework: FastAPI
- Inspired by: RAID systems, Erasure Coding in distributed storage