A complete microservices ecosystem built with Rust, featuring high-performance web servers, load balancing, rate limiting, analytics, and comprehensive monitoring.
- System Overview
- Architecture
- Components
- Prerequisites
- Setup & Running
- API Documentation
- Development
- Monitoring
- Troubleshooting
This project demonstrates a complete microservices architecture using Rust with the following features:
- Multiple backend services with identical APIs
- Load balancing with nginx
- Rate limiting
- Analytics processing
- Prometheus & Grafana monitoring
- Containerized with Docker
- PostgreSQL database integration
Directory structure:
.
├── .gitignore
├── analytics/ # Analytics service
├── docker-compose.yaml # Main Docker Compose file
├── init-db/ # Database initialization scripts
├── load-balancer/ # Load balancing service
├── Makefile # Main Makefile
├── monitoring/ # Prometheus and Grafana setup
│ ├── docker-compose.yml
│ ├── Makefile
│ ├── prometheus.yml
│ └── Setup.md
├── rate-limiter/ # Rate limiting service
├── Readme.md
├── server-1/ # First web server
│ ├── .dockerignore
│ ├── .env
│ ├── .gitignore
│ ├── Cargo.lock
│ ├── Cargo.toml
│ ├── docker-compose.yml
│ ├── Dockerfile
│ ├── Makefile
│ ├── Setup.md
│ ├── src/
│ │ ├── main.rs
│ │ ├── services.rs
│ │ ├── header.rs
│ │ ├── kafka.rs
│ │ └── prom.rs
│ ├── target/
│ └── Testing.md
└── server-2/ # Second web server with identical APIThe system consists of multiple containerized services that communicate with each other:
┌─────────────┐
│ │
┌────────▶ Monitor │
│ │ │
│ └─────────────┘
│
┌─────────┐ │ ┌─────────────┐ ┌─────────────┐
│ │ │ │ │ │ │
│ Client ├─────┼───────▶│ LoadBalancer├────────▶│ Server 1 │
│ │ │ │ │ │ │
└─────────┘ │ └──────┬──────┘ └──────┬──────┘
│ │ │
│ │ │
│ ┌──────▼──────┐ ┌──────▼──────┐
│ │ │ │ │
└────────┤ RateLimiter ├────────▶│ Server 2 │
│ │ │ │
└──────┬──────┘ └──────┬──────┘
│ │
│ │
┌──────▼──────┐ ┌──────▼──────┐
│ │ │ │
│ Analytics │◀────────┤ Database │
│ │ │ │
└─────────────┘ └─────────────┘Identical Rust servers built with Actix-web framework that handle the core business logic and expose the REST API. They connect to PostgreSQL for data persistence.
Key Technologies:
- Actix-web framework
- SQLX for PostgreSQL connection
- Prometheus for metrics
- Kafka integration
A Rust-based service that distributes traffic between Server 1 and Server 2, ensuring high availability and performance.
Key Features:
- Request routing
- Health checks
- Configurable through nginx.conf
Controls the rate of requests to protect the system from being overwhelmed.
Key Features:
- Request throttling
- Configurable limits
- Token bucket algorithm implementation
Processes data from other services and generates insights.
Key Technologies:
- Kafka consumer/producer
- Data processing pipeline
Provides comprehensive system monitoring using Prometheus and Grafana.
Key Features:
- Real-time metrics
- Custom dashboards
- Alert configuration
- Docker and Docker Compose
- Rust (for development)
- Make utility
- PostgreSQL client (for schema setup)
To start all the databases and services:
make databaseIndividual Component Setup (Open a terminal for each individual service and then run the following commands)
Server 1 and Server 2
cd server-1
makecd server-2
makeRate Limiter
cd rate-limiter
makeAnalytics
cd analyticsMonitoring
cd monitoringAccess Grafana dashboard Open http://localhost:3000 in your browser Default credentials: admin/admin
- URL: /todo
- Method: POST
- Request Body:
{
"title": "Finish the report",
"description": "Complete the quarterly sales report",
"status": "pending",
"due_date": "2024-10-30"
}- Response:
{
"id": 1,
"title": "Finish the report",
"description": "Complete the quarterly sales report",
"status": "pending",
"due_date": "2024-10-30",
"created_at": "2024-10-23T13:34:15.763336",
"updated_at": "2024-10-23T13:34:15.763336"
}- URL: /todos
- Method: GET
- Response:
[
{
"id": 1,
"title": "Finish the report",
"description": "Complete the quarterly sales report",
"status": "pending",
"due_date": "2024-10-30",
"created_at": "2024-10-23T13:34:15.763336",
"updated_at": "2024-10-23T13:34:15.763336"
}
]The system exposes the following metrics via Prometheus:
- HTTP request counts
- Request duration
- Error rates
- System resource usage
Access Grafana at http://localhost:3000 and use the following dashboards:
- System Overview - Core system metrics
- API Performance - Request rates and latencies
- Database Performance - Query performance and connection pools
To add new metrics:
- Define the metric in the relevant service's
prom.rsfile - Register and expose the metric
- Update the Prometheus scrape configuration if needed
- Create or update Grafana dashboards
Database Connection Errors Error:
Database(PgDatabaseError { severity: Error, code: "42P01", message: "relation \"todo\" does not exist" })Solution: Push the schema located in todo.sql to database:
psql -h localhost -U postgres -d postgres -f init-db/todo.sqlService Connection Issues If services can't connect to each other:
- Ensure necessary containers are running via:
docker-compose ps- Verify environment variables are correctly set in
.envfiles
Tested using
ohaCommand:
oha http://localhost:1234/todos -n 10000 -c 1000 Result:

