A distributed analytics system implemented in Rust that demonstrates key distributed systems concepts including fault tolerance, data partitioning, and distributed computation. The system uses consistent hashing for data partitioning and efficient metric distribution across worker nodes.
- Control Node: Handles incoming requests and routes metrics to appropriate worker nodes using consistent hashing
- Worker Nodes: Process and store metrics data, providing both individual and aggregated metrics
- Partitioning: Uses Jump Consistent Hashing for even distribution of metrics across workers
- Metrics: Utilizes HistogramVec for accurate metric aggregation and statistics
- Consistent hashing ensures same metrics always route to same worker
- Efficient metric aggregation with proper statistical distribution
- Scalable architecture supporting multiple worker nodes
- Real-time metric processing and aggregation
- Comprehensive logging and debugging capabilities
- Docker
- Docker Compose
- Postman (for testing)
- Clone the repository
- Navigate to the project directory
- Start the stack:
docker-compose up -dThis will start:
- Control Node: http://localhost:8080
- Worker Node 1: http://localhost:8081
- Worker Node 2: http://localhost:8082
All requests require the following header:
Authorization: Bearer local-dev-token-123GET /health
# Response
{
"status": "healthy",
"message": "[node] is operational"
}POST /metrics
Content-Type: application/json
{
"metric_name": "cpu_usage",
"value": 75.5
}
# Response
{
"success": true,
"message": "Metric recorded on worker X"
}GET /metrics/{name}
# Response
{
"metric_name": "cpu_usage",
"values": [75.5, 80.2, 70.1],
"timestamp": "2024-11-25T20:59:23.376Z"
}GET /metrics/{name}/aggregate
# Response
{
"metric_name": "cpu_usage",
"count": 3,
"sum": 225.8,
"mean": 75.27,
"min": 70.1,
"max": 80.2,
"timestamp": "2024-11-25T20:59:23.376Z"
}src/
├── api/ # API handlers for control and worker nodes
├── metrics/ # Metrics processing and aggregation logic
├── partitioning/ # Consistent hashing implementation
├── proto/ # Protocol buffer definitions
└── raft/ # Consensus implementation
-
Control Node
- Routes incoming metrics using consistent hashing
- Manages worker node coordination
- Handles API requests and responses
-
Worker Nodes
- Process and store assigned metrics
- Provide individual and aggregated metric data
- Maintain metric history and statistics
-
Partitioning
- Implements Jump Consistent Hashing
- Ensures even distribution of metrics
- Maintains consistency in routing
# Build the project
cargo build
# Run tests
cargo test
# Run with debug logging
RUST_LOG=debug cargo runThis project is licensed under the MIT License - see the LICENSE file for details.