A production-style distributed background job queue written in Go.
GoQ is a Redis-backed job queue inspired by systems like Sidekiq, BullMQ, and Asynq. It focuses on correctness under concurrency, crash recovery, and production reliability, rather than simply enqueueing and dequeuing jobs.
The project was built from scratch to demonstrate backend infrastructure engineering concepts including atomic Redis operations, worker coordination, lease-based crash recovery, retry scheduling, idempotent APIs, asynchronous persistence, and observability.
- Reliable job delivery using Redis leases
- Worker crash recovery
- Idempotent job creation
- Exponential retry with dead-letter queue
- Delayed & scheduled jobs
- Concurrent worker pool with graceful shutdown
- Batched asynchronous PostgreSQL audit logging
- Prometheus metrics
- Docker Compose deployment
- Race-tested Go implementation
Redis contains every hot-path data structure required for queue processing.
PostgreSQL is intentionally not part of the critical execution path—it stores an asynchronous audit history only, ensuring database latency never blocks workers.
Workers claim jobs atomically using Redis BRPOPLPUSH.
Jobs remain in the processing list until explicitly acknowledged, preventing message loss if a worker exits unexpectedly.
A background reaper scans expired leases and atomically returns abandoned jobs back to the queue using a Lua script.
Clients may include an Idempotency-Key header.
The key is atomically claimed before job creation, ensuring repeated HTTP requests return the original job instead of creating duplicates.
Failed jobs use exponential backoff:
2s
↓
4s
↓
8s
↓
Dead Letter Queue
Retries are scheduled through Redis sorted sets, preventing failing jobs from overwhelming downstream services.
Worker throughput is independent of PostgreSQL.
Audit events are buffered in memory and flushed in batches.
If PostgreSQL becomes unavailable, job execution continues uninterrupted.
| Component | Technology |
|---|---|
| Language | Go 1.25 |
| HTTP | net/http |
| Queue | Redis |
| Database | PostgreSQL |
| Metrics | Prometheus |
| Containers | Docker Compose |
| Redis Client | go-redis/v9 |
| PostgreSQL Driver | pgx/v5 |
| Method | Endpoint | Description |
|---|---|---|
POST |
/jobs |
Enqueue a new job |
GET |
/jobs/:id |
Retrieve job status |
GET |
/queues/:name/stats |
Queue statistics |
GET |
/metrics |
Prometheus metrics |
Example:
curl -X POST localhost:8080/jobs \
-H "Content-Type: application/json" \
-H "Idempotency-Key: abc123" \
-d '{
"queue":"emails",
"payload":"welcome-email",
"priority":1
}'git clone https://github.com/Tharun-bot/goq.git
cd goq
docker compose up -dThe compose stack starts:
- Redis
- PostgreSQL
- API server
- Worker
Configuration is environment-driven:
REDIS_URL
DATABASE_URL
API_PORT
go test ./internal/... -v -raceSubmits 1000 real jobs and verifies the queue completely drains.
API_URL=http://localhost:8080 ./scripts/smoke_test.shMeasured using Vegeta against POST /jobs.
| Rate | Requests | Success | p50 | p95 | p99 |
|---|---|---|---|---|---|
| 200/sec | 6,000 | 100% | 836µs | 1.48ms | 1.78ms |
| 2,000/sec | 30,000 | 100% | 616µs | 813µs | 1.16ms |
The enqueue API maintained 100% success with sub-2ms p99 latency under 10× higher load.
End-to-end processing was separately verified through a 1000-job smoke test that completely drained the queue.
The project was built incrementally, with each stage validated before moving to the next.
- Project scaffolding
- Redis queue implementation
- Concurrent worker pool
- Lease-based crash recovery
- Retry scheduling & dead-letter queue
- Delayed jobs
- REST API & idempotency
- PostgreSQL write-behind audit log
- Prometheus instrumentation
- Docker packaging & benchmarking
- Workers consume a single queue per process.
- Queue priorities are stored but not yet used during scheduling.
- Designed for a single deployment instance; distributed leader election is intentionally out of scope.
- Multi-queue worker scheduling
- Priority-aware dequeueing
- Distributed worker coordination
- Rate limiting
- Job cancellation
- Cron-style recurring jobs
- Web dashboard
- OpenTelemetry tracing
- Horizontal worker autoscaling
MIT
