Skip to content

yashk1103/LittleQ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LittleQ

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.

  1. SLA Assurance:  Little's Law to mathematically derive autoscaling thresholds, ensuring we scale before we breach user contracts, not just when CPU is high.
  2. Resilience: Implemented Circuit Breaking patterns like exponential backoff with jitter and Dead Letter Queues to prevent cascading failures.
  3. Concurrency: Used Go's primitives (channels/semaphores) for bounded parallelism to protect downstream resources.
  4. Observability: Instrumented with Prometheus to drive K8s HPA decisions based on custom business metrics."

Little's Law

L = lambda * W
  • L: Maximum queue depth
  • lambda: Arrival rate (jobs/second)
  • W: SLA wait time (seconds)

Quick Start

docker compose up -d redis
go run cmd/worker/main.go -queue=realtime
go run cmd/producer/main.go -queue=realtime -count=50

Real-Time Testing

Terminal 1 - Redis:

docker compose up redis

Terminal 2 - Monitor (live scaling decisions):

go run cmd/monitor/main.go -queue=realtime

Terminal 3 - Worker:

go run cmd/worker/main.go -queue=realtime

Terminal 4 - Producer:

go run cmd/producer/main.go -queue=realtime -count=50
go run cmd/producer/main.go -queue=realtime -count=100 -burst

Architecture

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

Configuration

SLAQueueConfig{
    Name:           "realtime",
    ArrivalRate:    20,
    SLASeconds:     1,
    JobsPerWorker:  5,
    ScaleThreshold: 0.7,
    MaxRetries:     3,
}

CLI Tools

Worker

go run cmd/worker/main.go -queue=realtime -concurrency=8 -redis=localhost:6379

Producer

go run cmd/producer/main.go -queue=realtime -count=100 -interval=50ms -burst

Monitor

go run cmd/monitor/main.go -queue=realtime -interval=2s

Metrics

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

Kubernetes

kubectl apply -f deployments/k8s/hpa.yaml

Queue Backends

Backend Queue Depth Metric
Redis LLEN
Kafka Consumer lag
SQS ApproximateNumberOfMessagesVisible

Tests

Test Files

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

Run All Tests

go test ./...

Verbose Output

go test ./... -v

Test Coverage

go test ./... -cover

Run Specific Package

go test ./internal/config -v
go test ./internal/autoscale -v
go test ./internal/retry -v

License

MIT

About

Fault-tolerant, high-performance distributed task queue in Go queue system that scales on math. Little's Law-based SLA enforcement with Redis/Kafka/SQS backend

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages