Composable background job engine for Go

Dispatch your jobs

Background jobs, durable workflows, cron scheduling, and distributed workers — out of the box.

$go get github.com/xraph/dispatch
Job
Queue
Execute
worker-01
200 Delivered
worker-02
503 Retry
worker-03
422 DLQ
Typed Handlers
Durable Workflows
DLQ + Replay
Cron Scheduling
Features

Everything you need for background processing

Dispatch handles the hard parts — retries, scheduling, dead letters, worker coordination — so you can focus on your business logic.

Background Jobs

Define typed handlers, enqueue with priority, and retry with configurable backoff. No event is lost, ever.

jobs.go
dispatch.Register("email.send",
dispatch.WithHandler(sendEmail),
dispatch.WithPriority(High),
dispatch.WithRetry(5),
)

Durable Workflows

Multi-step Go functions that checkpoint progress and resume after failure. No YAML, no DSL.

workflows.go
dispatch.Workflow("onboard.user",
dispatch.Step("validate", validateUser),
dispatch.Step("provision", provisionAccount),
dispatch.Step("notify", notifyUser),
)

Dead Letter Queue

Jobs that exhaust retries are captured automatically. Inspect, debug, and replay them on demand.

dlq.go
items, _ := d.DLQ().List(ctx,
dlq.WithJobType("email.send"),
dlq.WithLimit(10),
)
d.DLQ().Replay(ctx, items[0].ID)

Distributed Cron

Leader-elected cron scheduling with per-tenant support and runtime enable/disable.

cron.go
dispatch.Cron("daily.report",
dispatch.WithSchedule("0 9 * * *"),
dispatch.WithLeaderElection(true),
dispatch.WithTenant(tenantID),
)

Distributed Workers

Worker registration, heartbeats, leader election, and automatic work stealing across nodes.

workers.go
d.Workers().Register(ctx, dispatch.Worker{
ID: workerID,
Capacity: 10,
Heartbeat: 30 * time.Second,
})

Pluggable Stores

Ship with in-memory for dev, swap to PostgreSQL for production. Bring your own store with a simple interface.

main.go
d, _ := dispatch.New(
dispatch.WithStore(postgres.New(db)),
dispatch.WithWorkers(8),
dispatch.WithLogger(slog.Default()),
)
Execution Pipeline

From enqueue to execution. Automatically.

Dispatch orchestrates the entire job lifecycle — scheduling, execution, retries, and dead-letter routing.

Type-Safe Jobs

Every job is typed and validated before execution. Mismatched payloads fail at compile time, not runtime.

Priority Scheduling

Jobs are scheduled by priority and distributed to available workers. Each worker has independent capacity and backoff policies.

Outcome Routing

Success = completed. Transient error = retry with backoff. Exhausted retries = dead letter queue for inspection and replay.

Enqueue()
email.send
Schedulequeue
Executeprocess
worker-01
✓ Completed
worker-02
↻ Retry
worker-03
✗ → DLQ
Completed
Retry
DLQ
Disabled
Developer Experience

Simple API. Production power.

Enqueue your first job in under 20 lines. Handle typed payloads on the worker side with zero boilerplate.

Sender
main.go
1package main
2 
3import (
4 "log/slog"
5 "github.com/xraph/dispatch"
6 "github.com/xraph/dispatch/store/memory"
7)
8 
9func main() {
10 d, _ := dispatch.New(
11 dispatch.WithStore(memory.New()),
12 dispatch.WithWorkers(4),
13 dispatch.WithLogger(slog.Default()),
14 )
15 
16 "text-fd-muted-foreground/60 italic">// Register a typed job handler
17 dispatch.Register(d, "email.send", sendEmail)
18 
19 "text-fd-muted-foreground/60 italic">// Enqueue a job with options
20 d.Enqueue(ctx, dispatch.Job{
21 Type: "email.send",
22 Payload: emailJSON,
23 Priority: dispatch.High,
24 })
25}
Handler
handler.go
1package main
2 
3import (
4 "context"
5 "github.com/xraph/dispatch"
6)
7 
8type EmailInput struct {
9 To string `json:"to"`
10 Subject string `json:"subject"`
11 Body string `json:"body"`
12}
13 
14func sendEmail(
15 ctx context.Context,
16 job *dispatch.Job[EmailInput],
17) error {
18 input := job.Payload
19 
20 if err := mailer.Send(
21 input.To, input.Subject, input.Body,
22 ); err != nil {
23 "text-fd-muted-foreground/60 italic">// Mark transient errors as retryable
24 return dispatch.Retryable(err)
25 }
26 return nil
27}

Start dispatching jobs

Add production-grade background processing to your Go service in minutes. Dispatch handles scheduling, retries, dead letters, and worker coordination out of the box.

$go get github.com/xraph/dispatch