Skip to content

MonishJuspay/voice-orchestrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Voice Orchestrator

A production-ready Go microservice for orchestrating voice pod allocation and pool management in Kubernetes.

πŸ“‹ Overview

Voice Orchestrator consists of two independent services:

  1. Router Service - High-performance HTTP API for pod allocation
  2. Pool Manager Service - Background reconciliation worker for K8s pod management

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Voice Orchestrator                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   Router Service     β”‚      Pool Manager Service             β”‚
β”‚   (HTTP API)         β”‚      (Background Worker)              β”‚
β”‚                      β”‚                                       β”‚
β”‚ β€’ Fast allocation    β”‚ β€’ Reconciles desired vs actual pods   β”‚
β”‚ β€’ Multiple replicas  β”‚ β€’ Single replica only                 β”‚
β”‚ β€’ Reads from Redis   β”‚ β€’ Reads from Postgres                 β”‚
β”‚ β€’ Health checks      β”‚ β€’ Scales K8s deployments              β”‚
β”‚                      β”‚ β€’ Syncs Redis state                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚                           β”‚
           β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
           β”‚                           β”‚
        β”Œβ”€β”€β–Όβ”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚Redis β”‚    β”‚Postgres  β”‚    β”‚Kubernetesβ”‚
        β””β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

1. Merchant Config β†’ Postgres (merchants table with desired_pod_count)
                         ↓
2. Pool Manager reads Postgres every 10s
                         ↓
3. Pool Manager scales K8s deployments (if needed)
                         ↓
4. Pool Manager syncs Redis (merchant:{id}:pod_count)
                         ↓
5. Router reads Redis for fast pod allocation

πŸš€ Quick Start

Prerequisites

  • Go 1.25.7 (see Installation)
  • Docker (optional, for containerization)
  • kubectl (optional, for K8s deployment)
  • Redis (for caching)
  • PostgreSQL 16+ (for merchant data)
  • Kubernetes cluster (for production deployment)

Installation

Option 1: Automated Setup

# Clone the repository
git clone https://github.com/MonishJuspay/voice-orchestrator.git
cd voice-orchestrator

# Run setup script
./scripts/setup-dev.sh

# Edit environment variables
cp .env.example .env
nano .env

Option 2: Manual Setup

# Install Go 1.25.7 (Linux/macOS)
./scripts/install-go.sh

# Or download manually from https://go.dev/dl/

# Verify Go installation
go version  # Should show: go version go1.25.7 ...

# Download dependencies
make install-deps

Running Locally

Start Dependencies

# Start Redis
docker run -d -p 6379:6379 --name redis redis:alpine

# Start PostgreSQL
docker run -d -p 5432:5432 \
  -e POSTGRES_PASSWORD=postgres \
  -e POSTGRES_DB=voice_orchestrator \
  --name postgres postgres:16-alpine

Run Services

# Terminal 1: Run Router
make run-router

# Terminal 2: Run Pool Manager
make run-pool-manager

Verify Services

# Check Router health
curl http://localhost:8080/health

# Expected: {"status": "healthy"}

πŸ› οΈ Development

Build Commands

make help              # Show all available commands
make build             # Build both services
make build-router      # Build router only
make build-pool-manager # Build pool-manager only
make clean             # Clean build artifacts

Testing

make test              # Run tests with coverage
make test-coverage     # Generate HTML coverage report

Code Quality

make fmt               # Format code
make vet               # Run go vet
make lint              # Run golangci-lint
make verify            # Run all checks (fmt + vet + lint + test)

Docker

# Build Docker images
make docker-build

# Push to registry (set DOCKER_REGISTRY env var)
make docker-push

# Example with custom registry
DOCKER_REGISTRY=myregistry.io/myorg make docker-build

πŸ“¦ Deployment

Kubernetes Deployment

Prerequisites

# Ensure kubectl is configured
kubectl cluster-info

# Create namespace (optional)
kubectl create namespace voice-orchestrator

Deploy Services

# Deploy both services
make k8s-deploy

# Or deploy individually
make k8s-deploy-router
make k8s-deploy-pool-manager

Configure Secrets

# Edit secrets with real credentials
kubectl edit secret router-secret -n default
kubectl edit secret pool-manager-secret -n default

Verify Deployment

# Check pods
kubectl get pods -l app=voice-orchestrator

# Check services
kubectl get svc router-service

# View logs
kubectl logs -l component=router -f
kubectl logs -l component=pool-manager -f

Cleanup

make k8s-delete

πŸ”§ Configuration

All configuration is via environment variables. See .env.example for all options.

Router Service

Variable Description Default
ENVIRONMENT Environment (development/production) development
LOG_LEVEL Log level (debug/info/warn/error) info
HTTP_PORT HTTP server port 8080
HTTP_READ_TIMEOUT Read timeout 30s
HTTP_WRITE_TIMEOUT Write timeout 30s
REDIS_ADDR Redis address localhost:6379
POSTGRES_HOST Postgres host localhost
K8S_NAMESPACE K8s namespace default

Pool Manager Service

Variable Description Default
RECONCILE_INTERVAL Reconciliation interval 10s
REDIS_ADDR Redis address localhost:6379
POSTGRES_HOST Postgres host localhost
K8S_NAMESPACE K8s namespace default
K8S_IN_CLUSTER Running in K8s cluster false

πŸ“š API Documentation

Router Endpoints

Health Check

GET /health

Response:

{
  "status": "healthy"
}

Readiness Check

GET /ready

Response:

{
  "status": "ready",
  "redis": "ok",
  "postgres": "ok",
  "kubernetes": "ok"
}

Allocate Pods (TODO)

POST /api/v1/allocate
Content-Type: application/json

{
  "merchant_id": "merchant-123",
  "pod_count": 5
}

Response:

{
  "merchant_id": "merchant-123",
  "allocated_pods": [
    {
      "pod_id": "pod-1",
      "ip": "10.0.1.5",
      "status": "ready"
    }
  ]
}

Admin API (TODO)

  • POST /api/v1/admin/merchants - Create merchant
  • GET /api/v1/admin/merchants/:id - Get merchant
  • PUT /api/v1/admin/merchants/:id - Update merchant
  • DELETE /api/v1/admin/merchants/:id - Delete merchant

πŸ—οΈ Project Structure

voice-orchestrator/
β”œβ”€β”€ cmd/
β”‚   β”œβ”€β”€ router/              # Router entry point
β”‚   └── pool-manager/        # Pool manager entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ router/          # HTTP handlers & server
β”‚   β”‚   β”œβ”€β”€ poolmanager/     # Reconciliation logic
β”‚   β”‚   └── admin/           # Admin API handlers
β”‚   β”œβ”€β”€ datastore/
β”‚   β”‚   β”œβ”€β”€ redis/           # Redis client & operations
β”‚   β”‚   └── postgres/        # Postgres client & queries
β”‚   β”œβ”€β”€ domain/              # Domain models & DTOs
β”‚   β”œβ”€β”€ k8s/                 # Kubernetes client wrapper
β”‚   └── config/              # Configuration management
β”œβ”€β”€ pkg/
β”‚   └── logger/              # Structured logging (zap)
β”œβ”€β”€ deployments/
β”‚   β”œβ”€β”€ router/              # K8s manifests for router
β”‚   └── pool-manager/        # K8s manifests for pool-manager
β”œβ”€β”€ docker/                  # Dockerfiles
β”œβ”€β”€ scripts/                 # Helper scripts
β”œβ”€β”€ migrations/              # Database migrations
β”œβ”€β”€ Makefile                 # Build automation
β”œβ”€β”€ go.mod                   # Go module definition
└── README.md                # This file

πŸ§ͺ Testing

Run All Tests

make test

Run Specific Tests

go test -v ./internal/domain/...
go test -v ./internal/app/router/...

Coverage Report

make test-coverage
open coverage.html  # macOS
xdg-open coverage.html  # Linux

πŸ› Troubleshooting

Build Issues

Issue: go: cannot find module

# Solution: Download dependencies
make install-deps

Issue: Go version mismatch

# Solution: Install Go 1.25.7
./scripts/install-go.sh

Runtime Issues

Issue: Cannot connect to Redis

# Check Redis is running
docker ps | grep redis

# Start Redis if needed
docker run -d -p 6379:6379 --name redis redis:alpine

Issue: Cannot connect to Postgres

# Check Postgres is running
docker ps | grep postgres

# Start Postgres if needed
docker run -d -p 5432:5432 \
  -e POSTGRES_PASSWORD=postgres \
  -e POSTGRES_DB=voice_orchestrator \
  --name postgres postgres:16-alpine

Issue: K8s client error: unable to load in-cluster configuration

# Solution: Set K8S_IN_CLUSTER=false in .env
echo "K8S_IN_CLUSTER=false" >> .env

Kubernetes Issues

Issue: ImagePullBackOff

# Check image exists
docker images | grep voice-orchestrator

# Build and push images
make docker-build docker-push

Issue: CrashLoopBackOff

# Check logs
kubectl logs -l component=router --tail=50

# Check secrets
kubectl get secret router-secret -o yaml

πŸ“Š Monitoring & Observability

Logs

Structured JSON logging (production):

{
  "level": "info",
  "ts": "2024-01-15T10:30:45.123Z",
  "caller": "router/handler.go:45",
  "msg": "Request processed",
  "merchant_id": "merchant-123",
  "duration_ms": 15
}

Console logging (development):

2024-01-15T10:30:45.123Z  INFO  router/handler.go:45  Request processed  merchant_id=merchant-123 duration_ms=15

Metrics (Future)

  • Prometheus integration planned
  • Metrics endpoints: /metrics
  • Key metrics: request rate, latency, pod allocation success rate

🀝 Contributing

Development Workflow

  1. Clone repository

    git clone https://github.com/MonishJuspay/voice-orchestrator.git
    cd voice-orchestrator
  2. Setup environment

    ./scripts/setup-dev.sh
  3. Create feature branch

    git checkout -b feature/my-feature
  4. Make changes and test

    make verify  # Run all checks
  5. Commit and push

    git add .
    git commit -m "Add feature: description"
    git push origin feature/my-feature
  6. Create pull request

Code Standards

  • Format code: make fmt before committing
  • Pass linting: make lint must pass
  • Write tests: Maintain >80% coverage
  • Document changes: Update README if needed

πŸ“ License

Copyright Β© 2024 Juspay Technologies. All rights reserved.


πŸ™‹ Support


πŸ—ΊοΈ Roadmap

Current Status (v0.1.0)

βœ… Project structure and boilerplate
βœ… Configuration management
βœ… Logging infrastructure
βœ… Docker & Kubernetes manifests
βœ… CI/CD pipelines
⏳ Business logic implementation (in progress)

Planned Features

  • Complete pod allocation logic
  • Redis caching layer
  • Postgres repository implementation
  • K8s deployment scaling
  • Prometheus metrics
  • Admin UI
  • Rate limiting
  • Authentication & authorization
  • Database migrations
  • Grafana dashboards

Built with ❀️ using Go 1.25.7

About

Router and Pool Manager for Voice Reliability and Scalability

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors