A Distributed, Fault-Tolerant Inference Gateway for LLMs built with Go, gRPC, Kubernetes, and Terraform.
NeuroGate is not a chatbotβit's the platform that serves the chatbot. It provides:
- Load Balancing: Round-robin distribution across multiple LLM workers
- Fault Tolerance: Circuit breaker pattern to handle failing workers gracefully
- Observability: Prometheus metrics + Grafana dashboards for tokens/second, latency, etc.
- Cloud-Native: Kubernetes deployment with Terraform IaC
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENTS β
β curl / SDK / Web Application β
ββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β HTTP (REST)
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GATEWAY (Load Balancer) β
β ββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββββββββββ β
β β API Auth β β Round Robin LB β β Circuit Breaker (3 fails)β β
β ββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β gRPC
ββββββββββββββββββββΌβββββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Worker 1 β β Worker 2 β β Worker 3 β
β (gRPC Server) β β (gRPC Server) β β (gRPC Server) β
β :50051/:9090 β β :50052/:9092 β β :50053/:9093 β
ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ
β β β
ββββββββββββββββββββββ΄βββββββββββββββββββββ
β HTTP
βΌ
βββββββββββββββββββ
β Ollama β
β (LLM Engine) β
β :11434 β
βββββββββββββββββββ
neurogate/
βββ api/proto/ # gRPC Protocol Buffer definitions
βββ cmd/
β βββ gateway/ # Load Balancer REST API
β βββ worker/ # gRPC Worker connecting to Ollama
βββ deploy/
β βββ k8s/ # Kubernetes YAML manifests
β βββ terraform/ # Terraform IaC for K8s resources
β βββ prometheus/ # Prometheus configuration
βββ pkg/
β βββ circuitbreaker/ # Circuit Breaker pattern implementation
β βββ health/ # Health checking utilities
β βββ logger/ # Structured logging with slog
β βββ metrics/ # Prometheus instrumentation
β βββ ollama/ # Ollama API client
βββ Dockerfile.gateway # Multi-stage build for Gateway
βββ Dockerfile.worker # Multi-stage build for Worker
βββ docker-compose.yaml # Local development with Docker
βββ Makefile # Build automation
βββ go.mod # Go dependencies
- Go 1.22+
- Docker and Docker Compose
- Ollama (running locally with a model like
llama3.2) - Kind (optional, for Kubernetes)
- Terraform (optional, for IaC)
# Install Ollama (if not already)
brew install ollama
# Start Ollama and pull a model
ollama serve &
ollama pull llama3.2# Terminal 1: Start a worker
make run-worker
# Terminal 2: Start the gateway
make run-gateway
# Terminal 3: Test it!
make demo# Build and start all services
docker-compose up --build
# Test the gateway
curl -X POST http://localhost:8080/prompt \
-H "Content-Type: application/json" \
-H "Authorization: Bearer neurogate-secret-key-1" \
-d '{"query": "Explain quantum computing in simple terms"}'# Build Docker images
make docker
# Create Kind cluster and deploy
make kind-create
make deploy
# Check status
make status
# Test it
make demo-k8sGenerate text from the LLM.
Request:
curl -X POST http://localhost:8080/prompt \
-H "Content-Type: application/json" \
-H "Authorization: Bearer neurogate-secret-key-1" \
-d '{
"query": "Why is the sky blue?",
"model": "llama3.2",
"max_tokens": 500,
"temperature": 0.7
}'Response:
{
"request_id": "req-1704567890123456789",
"response": "The sky appears blue due to a phenomenon called Rayleigh scattering...",
"model": "llama3.2",
"tokens": 156,
"latency_ms": 2340,
"worker_id": "worker-0"
}Check gateway health status.
List all workers and their status including circuit breaker state.
| Metric | Type | Description |
|---|---|---|
neurogate_gateway_requests_total |
Counter | Total HTTP requests |
neurogate_gateway_request_duration_seconds |
Histogram | Request latency |
neurogate_gateway_circuit_breaker_state |
Gauge | CB state per worker |
neurogate_worker_inference_duration_seconds |
Histogram | LLM inference time |
neurogate_worker_tokens_generated_total |
Counter | Tokens generated |
neurogate_worker_tokens_per_second |
Gauge | Current TPS |
Access Grafana at http://localhost:3000 (admin/neurogate) with pre-configured dashboards showing:
- Requests per second
- P95 latency
- Tokens per second
- Circuit breaker states
Gateway:
| Variable | Default | Description |
|---|---|---|
HTTP_PORT |
8080 | HTTP listen port |
METRICS_PORT |
9091 | Prometheus metrics port |
WORKER_ADDRESSES |
localhost:50051 | Comma-separated worker addresses |
API_KEYS |
(none) | Comma-separated valid API keys |
LOG_LEVEL |
info | Log level (debug, info, warn, error) |
Worker:
| Variable | Default | Description |
|---|---|---|
GRPC_PORT |
50051 | gRPC listen port |
METRICS_PORT |
9090 | Prometheus metrics port |
OLLAMA_URL |
http://localhost:11434 | Ollama API URL |
LOG_LEVEL |
info | Log level |
The gateway implements a circuit breaker for each worker:
- Closed (normal): Requests flow through
- Open (tripped): After 3 consecutive failures, traffic stops for 30 seconds
- Half-Open (testing): One request allowed through to test recovery
[CLOSED] ββ3 failuresββ> [OPEN] ββ30s timeoutββ> [HALF-OPEN]
β² β
βββββββββββββsuccessββββββββββββββββββ β
β
βββββββββββββfailureββββββββββββββββββββββββββββββββ
make help # Show all available commands
# Development
make build # Build all binaries
make test # Run tests
make lint # Run linters
make clean # Clean build artifacts
# Docker
make docker # Build all Docker images
make docker-push # Push images to registry
# Kubernetes
make kind-create # Create Kind cluster
make deploy # Deploy to K8s
make undeploy # Remove from K8s
make status # Show deployment status
# Terraform
make tf-init # Initialize Terraform
make tf-apply # Apply Terraform changes
# Demo
make demo # Test local gateway
make demo-k8s # Test Kind gateway| Component | Technology | Enterprise Value |
|---|---|---|
| Language | Go 1.22+ | Cloud-native standard |
| Communication | gRPC + Protobuf | High-performance internal comms |
| Orchestration | Kubernetes (Kind) | Industry-standard container orchestration |
| IaC | Terraform | Infrastructure as code |
| AI Engine | Ollama | Local LLM inference |
| Observability | Prometheus + Grafana | Industry-standard monitoring |
| Patterns | Circuit Breaker | Resilience engineering |
MIT License - see LICENSE for details.
Built with β€οΈ for learning distributed systems and cloud-native development.