Leviathan

Leviathan is a distributed database system built on top of SQLite, designed for high availability and horizontal scaling. It uses a heart-node architecture where the heart service acts as a coordinator and load balancer, while node services handle the actual database operations.
ποΈ Architecture
βββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββ
β Client App βββββΆβ Heart Service βββββΆβ RabbitMQ β
β β β (Coordinator) β β (Write Queue) β
βββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Node 1 β β Consumer β
β (SQLite) β β Services β
βββββββββββββββββββ βββββββββββββββββββ
βββββββββββββββββββ
β Node 2 β
β (SQLite) β
βββββββββββββββββββ
βββββββββββββββββββ
β Node 3 β
β (SQLite) β
βββββββββββββββββββ
β¨ Features
- High Availability: Multiple node instances with health checking
- Load Balancing: Intelligent request routing based on node load
- Async Writes: Write operations are queued through RabbitMQ for consistency
- Sync Reads: Read operations are load-balanced across healthy nodes
- gRPC Communication: High-performance inter-service communication
- Prometheus Metrics: Built-in monitoring and observability
- Graceful Shutdown: Proper resource cleanup and connection handling
- Configuration Management: YAML-based configuration with validation
π Quick Start
Prerequisites
- Go 1.25+
- Task (task runner)
- RabbitMQ
- Protocol Buffers compiler (
protoc)
- Docker (optional, for containerized deployment)
Installation
git clone https://github.com/osamikoyo/leviathan.git
cd leviathan
task setup
Configuration
Copy and modify the example configurations:
cp configs/examples/heart.yaml heart_config.yaml
cp configs/examples/node1.yaml node_config.yaml
Running Services
-
Start RabbitMQ:
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
-
Start Heart Service:
task run-heart
-
Start Node Services:
task run-node
π οΈ Development
Available Task Commands
task # Show all available tasks
task build # Build both services
task test # Run tests
task test-coverage # Run tests with coverage
task lint # Run linter
task fmt # Format code
task proto # Generate protobuf code
task clean # Clean build artifacts
task ci # Full CI pipeline
task all # Complete development pipeline
# Infrastructure tasks
task start-rabbitmq # Start RabbitMQ container
task stop-rabbitmq # Stop RabbitMQ container
Project Structure
.
βββ cmd/ # Application entry points
β βββ heart/ # Heart service main
β βββ node/ # Node service main
βββ config/ # Configuration handling
βββ configs/ # Configuration examples
βββ errors/ # Common error definitions
βββ health/ # Health checking system
βββ heart/ # Heart service implementation
βββ heartcore/ # Heart business logic
βββ heartserver/ # Heart gRPC server
βββ logger/ # Logging utilities
βββ metrics/ # Prometheus metrics
βββ models/ # Data models
βββ producer/ # RabbitMQ producer
βββ proto/ # Protocol buffer definitions
βββ retrier/ # Retry logic utilities
βββ taskfile.yml # Task runner configuration
π Monitoring
Leviathan exposes Prometheus metrics on the following endpoints:
leviathan_requests_total - Total number of requests
leviathan_request_duration_seconds - Request processing time
leviathan_active_connections - Current active connections
leviathan_request_errors_total - Total number of errors
leviathan_node_health_status - Node health status (1=healthy, 0=unhealthy)
π§ Configuration
Heart Service Configuration
# Heart service configuration
addr: "localhost:8080" # Listen address
rabbitmq_url: "amqp://guest:guest@localhost:5672/"
exchange: "leviathan_writes" # RabbitMQ exchange
queue_name: "write_requests" # Queue name
# Node addresses for load balancing
nodes:
- "localhost:9001"
- "localhost:9002"
- "localhost:9003"
# Health checking configuration
health_check_interval: "30s" # Health check frequency
health_check_timeout: "5s" # Health check timeout
# Request handling configuration
max_retries: 3 # Maximum retry attempts
request_timeout: "30s" # Request timeout
π€ Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature)
- Commit your changes (
git commit -m 'Add some amazing feature')
- Push to the branch (
git push origin feature/amazing-feature)
- Open a Pull Request
Code Standards
- Follow Go conventions and best practices
- Write tests for new functionality
- Run
task ci before submitting PRs
- Keep functions under 100 lines
- Use meaningful variable and function names
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- SQLite team for the awesome embedded database
- gRPC team for high-performance RPC framework
- RabbitMQ team for reliable messaging
- Prometheus team for monitoring solution