Queue system with mathematical SLA guarantees using Little's Law. Bounded queue processing with Little's Law autoscaling and DLQ isolation. Queue flow control using Little's Law for predictable SLA compliance. Capacity-aware queue processor with Little's Law scaling.
- SLA Assurance: Little's Law to mathematically derive autoscaling thresholds, ensuring we scale before we breach user contracts, not just when CPU is high.
- Resilience: Implemented Circuit Breaking patterns like exponential backoff with jitter and Dead Letter Queues to prevent cascading failures.
- Concurrency: Used Go's primitives (channels/semaphores) for bounded parallelism to protect downstream resources.
- Observability: Instrumented with Prometheus to drive K8s HPA decisions based on custom business metrics."
L = lambda * W
- L: Maximum queue depth
- lambda: Arrival rate (jobs/second)
- W: SLA wait time (seconds)
docker compose up -d redis
go run cmd/worker/main.go -queue=realtime
go run cmd/producer/main.go -queue=realtime -count=50Terminal 1 - Redis:
docker compose up redisTerminal 2 - Monitor (live scaling decisions):
go run cmd/monitor/main.go -queue=realtimeTerminal 3 - Worker:
go run cmd/worker/main.go -queue=realtimeTerminal 4 - Producer:
go run cmd/producer/main.go -queue=realtime -count=50
go run cmd/producer/main.go -queue=realtime -count=100 -burst| Component | Purpose |
|---|---|
| config | SLA definitions with Little's Law calculations |
| queue | Pluggable backends (Redis, Kafka, SQS) |
| worker | Semaphore-based concurrency control |
| retry | Exponential backoff with DLQ |
| autoscale | Queue-depth based scaling logic |
| metrics | Prometheus instrumentation |
SLAQueueConfig{
Name: "realtime",
ArrivalRate: 20,
SLASeconds: 1,
JobsPerWorker: 5,
ScaleThreshold: 0.7,
MaxRetries: 3,
}go run cmd/worker/main.go -queue=realtime -concurrency=8 -redis=localhost:6379go run cmd/producer/main.go -queue=realtime -count=100 -interval=50ms -burstgo run cmd/monitor/main.go -queue=realtime -interval=2s| Metric | Type | Description |
|---|---|---|
| sla_jobs_processed_total | Counter | Jobs processed by status |
| sla_queue_depth | Gauge | Current queue depth |
| sla_job_duration_seconds | Histogram | Processing duration |
| sla_breaches_total | Counter | SLA violations |
kubectl apply -f deployments/k8s/hpa.yaml| Backend | Queue Depth Metric |
|---|---|
| Redis | LLEN |
| Kafka | Consumer lag |
| SQS | ApproximateNumberOfMessagesVisible |
| Package | File | Coverage |
|---|---|---|
| config | internal/config/config_test.go |
Little's Law calculations |
| autoscale | internal/autoscale/scaler_test.go |
Scaling decisions |
| retry | internal/retry/retry_test.go |
Backoff logic |
go test ./...go test ./... -vgo test ./... -covergo test ./internal/config -v
go test ./internal/autoscale -v
go test ./internal/retry -vMIT