Available for consulting: payments, backend performance and platform engineering.Book a call
Saravana Thiyagarajan · The Backend Guy
Book a call
Open source · Go library

GoQueue: a background job queue for Go that grows with you.

GoQueue is my open-source job queue library for Go. You write a job once, run it in memory while you develop, and move it to Redis, PostgreSQL, MySQL or AWS SQS in production by changing one line of config. It has 250+ stars on GitHub and is MIT licensed.

View on GitHub
Quick start

Install it and dispatch your first job.

Jobs are plain Go structs with a Process method. Register the type so workers can rebuild it from the queue, start some workers, and dispatch.

go get github.com/saravanasai/goqueue

type EmailJob struct {
    To      string `json:"to"`
    Subject string `json:"subject"`
}

func (e EmailJob) Process(ctx context.Context) error {
    fmt.Printf("Sending email to %s: %s\n", e.To, e.Subject)
    return nil
}

func init() {
    goqueue.RegisterJob("EmailJob", func() goqueue.Job { return &EmailJob{} })
}

func main() {
    cfg := config.NewInMemoryConfig() // or NewRedisConfig, NewPostgresConfig, NewSQSConfig
    q, err := goqueue.NewQueueWithDefaults("email-queue", cfg)
    if err != nil {
        log.Fatal(err)
    }
    q.StartWorkers(context.Background(), 2)
    q.Dispatch(EmailJob{To: "[email protected]", Subject: "Welcome"})
}

The full example, with graceful shutdown, is in the README. API docs are on pkg.go.dev.

Backends

One API, five backends.

Your job code and your Dispatch calls stay the same whichever backend you pick. Only the config changes.

BackendConfigGood for
In-memoryconfig.NewInMemoryConfig()Local development and tests. Nothing to install.
Redisconfig.NewRedisConfig(addr, password, db)Production queues when you already run Redis.
PostgreSQL / MySQLconfig.NewPostgresConfig(dsn), config.NewMySQLConfig(dsn)Teams that want jobs in the database they already back up. GoQueue creates its own tables, including the dead-letter queue.
AWS SQSconfig.NewSQSConfig(url, region, key, secret)Cloud workloads on AWS. SQS caps delayed jobs at 15 minutes.
Features

Retries, dead letters and the other things you need in production.

A failed job is retried up to a limit you set, with a fixed delay or exponential backoff. When it runs out of attempts it goes to a dead-letter queue, where you can inspect it instead of losing it. Jobs can be delayed with DispatchWithDelay.

You control the number of worker goroutines and how many jobs run at once. Middleware wraps every job, which is where logging, timing or panic recovery belongs. A metrics callback reports each job's duration and error, and Shutdown lets workers finish what they started before the process exits.

cfg := config.NewRedisConfig("localhost:6379", "", 0)
cfg = cfg.WithMaxWorkers(5)                // worker goroutines
cfg = cfg.WithConcurrencyLimit(10)         // jobs running at once
cfg = cfg.WithMaxRetryAttempts(3)          // then the job goes to the DLQ
cfg = cfg.WithRetryDelay(5 * time.Second)  // base delay between retries
cfg = cfg.WithExponentialBackoff(true)     // longer waits each time

q.DispatchWithDelay(job, 5*time.Minute)    // run it later
  • Go 1.18+
  • Redis
  • PostgreSQL
  • MySQL
  • AWS SQS
  • Dead-letter queue
  • Exponential backoff
  • Middleware
  • MIT
Compared with

GoQueue, Asynq, River and Temporal.

Asynq is Redis only and has a good web UI and CLI. River is built on PostgreSQL and can enqueue a job in the same transaction as your data. Temporal is a workflow engine for long, stateful processes; it is far more powerful and needs its own cluster.

I built GoQueue for the case in between: you want a plain job queue, you don't want to commit to one backend on day one, and you might end up on SQS. If you need a UI today, Asynq is ahead. If every job must commit with your data, River's transactional enqueue is the stronger guarantee.

Have a backend or payments problem to solve?

Tell me what you are building and where it hurts. I reply within one working day, usually with a time for a 30-minute call.