A high-performance microservices system for monitoring Uniswap V3 Concentrated Liquidity Pools on Ethereum, developed as part of an MBA thesis at USP/Esalq.
┌─────────────────────────────────────┐
│ External Clients │
└─────────────────┬───────────────────┘
│ HTTPS (8080)
┌─────────────────▼───────────────────┐
│ KrakenD API Gateway │
│ • JWT Validation │
│ • Rate Limiting │
│ • CORS / Security │
└─────────────────┬───────────────────┘
│
┌──────────────┬───────────────────┼───────────────────┬──────────────┐
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌─────────────┐ ┌───────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Auth │ │ Tracker │ │ Analytics │ │ Saga │ │ Redis │
│ (HTTP) │ │ (gRPC) │ │ (gRPC) │ │Orchestrator │ │ (Cache) │
│ :8081 │ │ :50051 │ │ :50052 │ │ │ │ :6379 │
└──────┬──────┘ └─────┬─────┘ └──────┬──────┘ └─────────────┘ └─────────────┘
│ │ │
▼ ▼ │
┌─────────────┐ ┌─────────────┐ │ ┌─────────────────────────────┐
│ PostgreSQL │ │ SQLite │◄─────────┘ │ Monitoring Stack │
│ (Auth) │ │ (Events) │ │ Prometheus :9090 │
└─────────────┘ └─────────────┘ │ Grafana :3000 │
└─────────────────────────────┘
Subscribes to Uniswap V3 pool events on Ethereum.
Features:
- Swap, Mint, Burn event decoding
- Checkpoint-based resumption (12-block intervals)
- Multi-pool support
- gRPC API for event queries
Tech: go-ethereum, SQLite, gRPC
Computes on-chain metrics from indexed events.
Features:
- TWAP: Time-Weighted Average Price calculation
- Liquidity Distribution: Tick-range liquidity aggregation
- Pool Stats: Volume, fees, event counts
Tech: gRPC, Redis (caching)
Handles user authentication and JWT tokens.
Features:
- User registration with bcrypt password hashing
- JWT access tokens (HS256)
- Session management with refresh tokens
Tech: Go-Fiber, JWT
Manages distributed transactions with fault tolerance.
Features:
- Circuit Breaker: Prevents cascade failures
- Saga Pattern: Compensating transactions on failure
- Retry Logic: Exponential backoff
Single entry point for all external requests.
Features:
- JWT validation
- Rate limiting (per IP/client)
- CORS configuration
- Request routing
| Layer | Technology |
|---|---|
| Language | Go 1.21+ |
| API Gateway | KrakenD 2.5 |
| Internal Communication | gRPC + Protocol Buffers |
| External API | REST (via gateway) |
| Databases | PostgreSQL (auth), SQLite (events), Redis (cache) |
| Authentication | JWT (HS256) |
| Security | mTLS (internal), Zero-Trust |
| Monitoring | Prometheus, Grafana |
| Infrastructure | Docker, Docker Compose |
- Go 1.21+
- Docker & Docker Compose
- OpenSSL (for certificate generation)
git clone <repository>
cd sagaindexer
# Generate mTLS certificates
cd gateway/certs
./generate.sh
cd ../..cp .env.example .env
# Edit .env with your values:
# - RPC_URL: Ethereum RPC endpoint (e.g., Infura)
# - POOL_ADDRESSES: Comma-separated pool addresses
# - JWT_SECRET: 32+ character secretgo test ./... -vdocker-compose up --build# Health check
curl http://localhost:8080/health
# Register user
curl -X POST http://localhost:8080/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"securepass123"}'
# Login
curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"securepass123"}'
# Get pool stats (with JWT)
curl http://localhost:8080/api/v1/pools/0x8ad599c3.../stats \
-H "Authorization: Bearer <token>"| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/auth/register |
Register new user |
| POST | /api/v1/auth/login |
Login, receive JWT |
| POST | /api/v1/auth/refresh |
Refresh access token |
| POST | /api/v1/auth/logout |
Invalidate session |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/pools/{pool}/twap |
Get TWAP for pool |
| GET | /api/v1/pools/{pool}/liquidity |
Get liquidity distribution |
| GET | /api/v1/pools/{pool}/stats |
Get pool statistics |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/pools/{pool}/events |
Get pool events |
| GET | /api/v1/checkpoints |
Get indexing progress |
sagaindexer/
├── gen/proto/ # Generated protobuf code
│ ├── analytics/v1/
│ ├── auth/v1/
│ └── tracker/v1/
├── shared/proto/ # Proto definitions
│ ├── analytics/v1/analytics.proto
│ ├── auth/v1/auth.proto
│ └── tracker/v1/tracker.proto
├── gateway/ # API Gateway
│ ├── config/krakend.json
│ ├── certs/ # mTLS certificates
│ └── Dockerfile
├── services/
│ ├── auth/ # Auth Service
│ │ ├── cmd/main.go
│ │ └── internal/
│ │ ├── config/
│ │ ├── domain/
│ │ ├── handler/
│ │ ├── jwt/
│ │ └── repository/
│ ├── tracker/ # Tracker Service
│ │ ├── cmd/main.go
│ │ └── internal/
│ │ ├── config/
│ │ ├── domain/
│ │ ├── grpc/
│ │ ├── http/
│ │ ├── repository/
│ │ └── subscriber/
│ ├── analytics/ # Analytics Service
│ │ ├── cmd/main.go
│ │ └── internal/
│ │ ├── calculator/
│ │ ├── config/
│ │ ├── grpc/
│ │ └── http/
│ └── saga/ # Saga Orchestrator
│ ├── cmd/main.go
│ └── internal/
│ ├── circuitbreaker/
│ ├── orchestrator/
│ └── repository/
├── docker-compose.yml
├── go.mod
├── go.sum
├── Makefile
└── README.md
# Run all tests
go test ./... -v
# Run with coverage
go test ./... -cover
# Run specific service tests
go test ./services/tracker/... -v
go test ./services/analytics/... -v
go test ./services/auth/... -v
go test ./services/saga/... -vTest Coverage: 236 tests across all services
make proto # Generate protobuf code
make test # Run all tests
make test-cover # Run tests with coverage
make build # Build all service binaries
make certs # Generate mTLS certificates
make docker-build # Build Docker images
make docker-up # Start all services
make docker-down # Stop all services
make docker-logs # Follow service logs
make clean # Remove build artifactsmake protoUpdate POOL_ADDRESSES in .env:
POOL_ADDRESSES=0x8ad599c3...,0x88e6A0c2...
cb := circuitbreaker.New("service-name", circuitbreaker.Config{
FailureThreshold: 5, // Opens after 5 failures
ResetTimeout: 30*time.Second, // Half-open after 30s
HalfOpenMaxRequest: 1, // Allow 1 request in half-open
})- All internal services communicate via gRPC with mTLS
- Only the API Gateway is exposed externally
- JWT validation on every protected endpoint
- Rate limiting prevents abuse
cd gateway/certs
./generate.shGenerates:
ca.crt/ca.key- Certificate Authoritygateway.crt/gateway.key- Gateway certificatetracker.crt/tracker.key- Tracker certificateanalytics.crt/analytics.key- Analytics certificateauth.crt/auth.key- Auth certificate
The project includes built-in observability:
# Start all services including monitoring
make docker-up
# Access dashboards
# Prometheus: http://localhost:9090
# Grafana: http://localhost:3000 (admin/sagaindexer)| Metric | Description |
|---|---|
http_requests_total |
Total HTTP requests by service/method/status |
http_request_duration_seconds |
Request latency histogram |
grpc_requests_total |
Total gRPC requests |
tracker_events_processed_total |
Blockchain events processed |
tracker_blocks_indexed |
Latest block indexed per pool |
circuit_breaker_state |
Circuit breaker state (0=closed, 1=open, 2=half-open) |
saga_executions_total |
Saga executions by status |
Each service exposes /metrics for Prometheus scraping:
- Auth:
http://auth:8081/metrics - Tracker HTTP:
http://tracker-http:8083/metrics - Analytics HTTP:
http://analytics-http:8082/metrics
This project was developed as part of an MBA thesis at USP/Esalq (Universidade de São Paulo - Escola Superior de Agricultura Luiz de Queiroz).
- Microservices Architecture
- Domain-Driven Design (DDD)
- Event Sourcing
- Circuit Breaker Pattern
- Saga Pattern for Distributed Transactions
- gRPC vs REST Performance
- Zero-Trust Security Model
MIT License - See LICENSE for details.
- Fork the repository
- Create a feature branch
- Write tests for new functionality
- Ensure all tests pass
- Submit a pull request
Author: Developed for USP/Esalq MBA Program Year: 2025