A production-grade, distributed job orchestration engine built in Go, emphasizing explicit concurrency, resiliency patterns, and cloud-native readiness.
This service accepts asynchronous jobs via REST APIs, persists their metadata, and processes them using a bounded worker pool. It implements standard distributed systems patterns to ensure reliability when interacting with downstream services.
- API Layer: Echo-based REST server handles job submission and status tracking.
- Worker Pool: A bounded pool of goroutines using explicit concurrency patterns (channels, WaitGroups).
- Persistence Layer: Abstracted
Storeinterface (implemented with an in-memoryMockStorefor demo, designed for Postgres). - Resiliency Layer: Integrated Circuit Breaker, Exponential Backoff Retries, and Rate Limiting.
- Observability Layer: Structured JSON logging (zerolog) and Prometheus metrics.
graph TD
API[REST API /jobs] -->|Enqueue| DB[(Postgres)]
API -->|Signal| Dispatcher[Job Dispatcher]
Dispatcher -->|Work| WorkerPool[Bounded Worker Pool]
WorkerPool -->|Downstream Call| SvcA[Service A]
WorkerPool -->|Downstream Call| SvcB[Service B]
WorkerPool -->|Aggregation| Aggregator[Result Aggregator]
Aggregator -->|Update Status| DB
- Go: 1.22 or higher
- Docker: For containerized deployment
- Terraform / Helm: For infrastructure and K8s deployment (optional)
go mod downloadgo run cmd/server/main.gogo test -v -race ./...curl -X POST http://localhost:8080/jobs \
-H "Content-Type: application/json" \
-H "X-Correlation-ID: job-123" \
-d '{"type": "ekyc-verification", "payload": {"user_id": 456}}'# Replace {id} with the ID from the submit response
curl http://localhost:8080/jobs/{id}# Liveness/Readiness
curl http://localhost:8080/health
# Prometheus Metrics
curl http://localhost:8080/metrics- Backpressure: Returns
429 Too Many Requestswhen the internal job queue is saturated. - Circuit Breaker: Trips after a 60% failure rate over 3 requests, protecting downstream systems.
- Graceful Shutdown: Allots 20 seconds for in-flight jobs to complete during termination.
- Structured Logs: Every log entry contains
correlation_id,job_id, andworker_idfor easy debugging. - Metrics:
active_workers_count: Real-time worker utilization.job_processing_duration_seconds: Histogram of processing latency.job_queue_depth: Monitor for consumer lag.
- Docker:
docker build -t scheduler . - Kubernetes: Manifests located in
deployments/k8s-manifests.yaml. - Terraform: AWS and GCP modules in
terraform/.
Developed as a production-grade template for distributed orchestration in Go.